3 ms·
NULL is guaranteed to equal integer 0 by standard, and converting 0 to a pointer is guaranteed to be a NULL pointer. > An integer constant expression with the
by dpedu 6y ago
NULL is guaranteed to equal integer 0 by standard, and converting 0 to a pointer is guaranteed to be a NULL pointer.
> An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant. If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function.
- layer8 6y agoAn integer constant expression is a syntactical construct, not a runtime entity. The C standard provides no guarantee that bytes (chars) with value zero can be read from memory as a null pointer.
- adamrezich 6y agowait what? my C is a bit rusty but when would reading 0 from memory & casting to a (void?) pointer type ever != NULL?
- layer8 6y agoC implementations are allowed to use a not-all-bits-zero representation for null pointer values. They are merely required to convert integer constant expressions with value zero to a null pointer value — regardless of how the resulting null pointer value is represented in memory. See also these FAQs: http://c-faq.com/null/machnon0.html http://c-faq.com/null/machnon0.html http://c-faq.com/null/machexamp.html http://c-faq.com/null/machexamp.html