K
Keith Thompson
[...]
You might consider the language incompatible with the architecture if
it said anything about what happened when address 0 was accessed, but
C doesn't do that. There is no necessary connection between C's null
pointer and the architecture's address 0, though they are the same in
most implementations. In particular, there's no reason that
(volatile unsigned char*)0x00
produce the architecture address 0. It could produce, say, 0xffffffff.
[...]
If one needed a pointer of address 0 in such a case, say where an
architecture had a register at 0 and whose null pointer was non-zero, one
subtract 1 from a char* of address 1:
char* addr_0 = (char*) 1 - 1;
That's one approach. Another is to use a non-constant expression:
int non_constant_zero = 0;
char *addr_0 = (char*)non_constant_zero;
(You could even declare non_constant_zero as const if you wanted to
confuse your readers.)