Octocontrabass wrote:
so there is no standards-compliant way to access memory address 0 with GCC (since it's equivalent to a null pointer).
I thought about this for a while: Wouldn't the easiest be to hide the fact that a pointer is NULL from GCC? So I thought, maybe write a function that returns a null pointer in assembler and call that. But that wouldn't work, since the resulting pointer would compare equal to a null pointer, and therefore accessing it is UB. So yeah, there is no valid way to access address 0 in C, as long as in your C implementation, address 0 is the null pointer. For that reason, and a bunch of other ones:
Octocontrabass wrote:
Personally, I would recommend never mapping anything at address 0.
I wholeheartedly concur.
Or, to put this another way:
PeterX wrote:
How does one get around that problem?
By writing a C compiler that does not represent null pointers as pointers to address zero. That is harder than it seems, since converting from integer to pointer now is no longer a no-op (converting integer 0 to pointer type must result in a null pointer). But this way you can actually tell between address 0 and a null pointer. Otherwise it is undefined.