NULL v. zero
Posted Jul 15, 2004 11:38 UTC (Thu) by
ikm (subscriber, #493)
Parent article:
NULL v. zero
The ISO/IEC 9899:1999 standard states that
1) as of the language: 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. [6.3.2.3.3]
2) as of the libraries: NULL is a macro that expands to the implementation-defined null pointer constant. [7.17.3]
These two statements clash a bit -- the null pointer constant is not an implementation defined, but rather a standards-defined.
It is obvious therefore that NULL is always #defined as 0 or ((void *)0).
It is totally correct to use 0 to initialize pointers to zero. That's what the standard states. With all due respect, Linus should have read the C standard before stating the contrary.
(
Log in to post comments)