Valid for dereferencing a literal with an integer as a pointer in C

Is it portable / valid C for dereferencing an integer literal, considered an address? those. if I want to set a 64-bit value to a memory address 0x12345678- 123this is the following portable and valid C, at least according to the C89 standard:

*(uint64_t *)(0x12345678) = 123ULL;

I do not see compiler warnings (checked using gcc -std=c89 -Wall input.c), but I recall a question on this issue some time ago, when the case was made of storing the address in an intermediate variable, rather than directly deleting the reference to the integer literal (which was added to the pointer address).

+4
source share
1 answer

, 0x12345678 uint64_t, . . , , , .

C99. , , uint64_t* C89:)

+3

Source: https://habr.com/ru/post/1665250/


All Articles