May an implementation define forms of null pointer constant other than
the ones specified in the standard?
C99 18.104.22.168p3 says:
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
C99 7.17p3 (describing <stddef.h>) says:
The macros are
which expands to an implementation-defined null pointer constant;
It has been argued elsewhere that the phrase "implementation-defined
null pointer constant" in 7.17p3 implies that an implementation may
define other forms of null pointer constant, for example (void*)42.
The fact that there are other definitions in the standard that aren't
actually exhaustive adds some plausibility to this argument.
The counterargument is that the phrase "implementation-defined null
pointer constant" merely means that the implementation may choose (and
must document) which of the allowed forms of null pointer constant it
uses as the expansion of NULL. If the standard intended to allow
other forms, 22.214.171.124p3 would have been a much better place to say so.
There is a visible effect. If an implementation is *not* allowed to
define other forms of null pointer constant, then any conforming
implementation must issue a diagnostic for the declaration of
func_ptr_2 in the following:
void (*func_ptr_1)(void) = (void*)0;
* Legal, since (void*)0 is a null pointer constant
void (*func_ptr_2)(void) = (void*)42;
* If (void*)42 is a null pointer constant, this is legal.
* Otherwise, it's a constraint violation.
If it is allowed, then a conforming implementation that documents
(void*)42 as a null pointer constant would not be required to issue a
What is the intent?
Keith Thompson (The_Other_Keith) XXXX@XXXXX.COM < http://www.yqcomputer.com/
San Diego Supercomputer Center <*> < http://www.yqcomputer.com/
We must do something. This is something. Therefore, we must do this.