"Malcolm McLean" <> writes:
[...]
> Surely there is some rule that NULL can be used as the null pointer
> constnant, in all contexts?
NULL is (or, rather, expands to) a null pointer constant in all
contexts. But a null pointer constant doesn't necessarily result in a
null pointer value in all contexts.
For example:
printf("%p\n", 0);
0 is a null pointer constant, but since it corresponds to the ",..."
in the declaration of printf, the compiler doesn't convert it from int
to any pointer type, and the call passes a value of type int. It
could be passed as the wrong value, the wrong size, or even in the
wrong location. If NULL is defined as 0, which is both legal and
common, then the above is equivalent to:
printf("%p\n", NULL);
To be safe, you need a cast:
printf("%p\n", (void*)NULL);
--
Keith Thompson (The_Other_Keith)
<http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"