3 ms·
> NULL is only slightly special as a pointer value: if we look in stddef.h, we can see that it's just defined to be the pointer with value 0. Your C compiler i
by nickcw 5y ago
> NULL is only slightly special as a pointer value: if we look in stddef.h, we can see that it's just defined to be the pointer with value 0.
Your C compiler is at liberty to use a different value than 0 for the actual NULL pointer stored in memory or in a register. It has to pretend to you that it is 0, but could be 0xDEADBEEF in reality.
Before ANSI C, NULL was #define-d as the actual bit value required. In modern C NULL is always 0.
In all the modern architectures I can think of a NULL pointer is represented by a value with all bits 0, but there are lots of examples of older architectures where this wasn't true.
There is a section in the comp.lang.c FAQ about this:
http://c-faq.com/null/machexamp.html http://c-faq.com/null/machexamp.html
- Filligree 5y agoNeeding to care about a wart that's only there due to 40 year old, dead architectures is yet another problem with C. At least in this case the standard goes to some length to make sure you don't have to care.
- SAI_Peregrinus 5y ago40-year old dead architectures like Android on 64-bit ARM?[1] Pointer tagging isn't that rare, and as memory expands in practice I'd expect we might even end up wanting >64-bit systems to allow for >48-bit real address spaces and/or >16-bit tags. The C standard means you don't have to care that there might actually be 2^8 NULL pointers since you're running on ARM with Top Byte Ignore in use. [1]https://source.android.com/devices/tech/debug/tagged-pointers https://source.android.com/devices/tech/debug/tagged-pointer...