Sebastian Redl wrote: > Laurent GUERBY wrote: >> Just curious: is there a "portable" way to read from memory >> address zero in C code? "portable" here means likely to work >> on most compilers without exotic compile flags in 2009. >> > For C++, in *theory*, a reinterpret_cast<void*>(0) yields a pointer with > the value 0 that is not recognized as the null pointer. > > For C and C++, the same thing can be achieved by casting an integer > variable with the value 0 to a pointer. (You only get the null pointer > constant by casting an integral constant expression with value 0.)
I don't believe it. A non-constant integer expression with the value 0, converted to a pointer, gives implementation-defined behaviour. One of the possible implementation-defined results is a null pointer. Which is just as well, really. Andrew.