[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: c-strtod: improve error checking
From: |
Peter Seebach |
Subject: |
Re: c-strtod: improve error checking |
Date: |
Wed, 21 Jan 2009 17:15:05 -0600 |
In message <address@hidden>, 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