3 ms·
Nobody says that NULL has to be 0. C's NULL is just a pointer value that can be compared for equality but can not be used for pointer arithmetic or be dereferen
by zAy0LfpBZLC8mAC 11y ago
Nobody says that NULL has to be 0. C's NULL is just a pointer value that can be compared for equality but can not be used for pointer arithmetic or be dereferenced. Implementations commonly reserve some address (often 0) to represent that pointer value, as that is just the most efficient way to do it (rather than making pointers larger than the normal word size to be able to represent the sentinel value)--also, object sizes are limited to one less than the number of possible addresses anyway, simply because you can have objects that are 0-sized.
- avian 11y agoFrom the point of view of C, it seems that NULL is indeed always defined as 0. At least according to the C FAQ: http://c-faq.com/null/machnon0.html http://c-faq.com/null/machnon0.html It might be that the internal representation used by the compiler is different, but from C a NULL pointer will always be equal to 0. See also: http://c-faq.com/null/ptrtest.html http://c-faq.com/null/ptrtest.html
- zAy0LfpBZLC8mAC 11y agoWell, yes, but from the view of C, pointer values are arbitrary anyway. There is no guarantee that a particular pointer's value has any particular relationship to which RAM cell of your hardware you are accessing.
- masklinn 11y agoYou're confusing a "null constant" and a null pointer. An integral 0 being converted to a pointer at runtime is not required to be a null pointer, only an integral 0 converted at compile time is.