In message <200901212258.n0lmwqx07...@f7.net>, Karl Berry writes:
>I am surprised.  I thought 0 was supposed to be a valid null pointer in
>all contexts, without casting.

0 is a null pointer constant.  In a context where the language anticipates
a pointer, a null pointer constant becomes a null pointer.  This means that
it's normally safe to write 0 and expect the language to treat it as a null
pointer, but it's quite possible to create contexts in which it isn't:

        printf("%p\n", 0);

This isn't guaranteed to work, because variable argument lists aren't
prototyped, so the compiler has no knowledge that it has to convert the 0
into a null pointer.

In other contexts, it's pretty much useless to cast 0s.  Note that NULL could
be the same, or it could be already converted to (void *), so it depends on
the implementation whether:

        printf("%p\n", NULL);

is legit.  (Which means it's not portable...)

-s


Reply via email to