*(NULL)
is always a constraint violation. *(NULL)
as a full expression is "not compilable" in C under any definition of NULL
. NULL
can be defined an integral zero, which is obviously not dereferencible. NULL
can be defined as integral zero cast to void *
type, but dereferencing void *
pointers is illegal in C.
Note: I'm still not entirely sure whether my statement above about dereferencing void *
pointer is correct. Is it a constraint violation or not? The standard does not spell it out explicitly. But at the same time it defines the behavior of unary *
for pointers to functions and pointers to objects only. Meanwhile, void
is not an object type.
If it is indeed legal to dereference void *
pointers, then *(NULL)
by itself would produce undefined behavior (assuming (void *) 0
definition of NULL
). But there is still one context in which *(NULL)
might be valid as a subexpression. It is &*(NULL)
. The language gives special treatment to &*
combination, making it a no-op with well-defined behavior even in situations where *
alone would produce undefined behavior.