Christian Bau <> writes:
> In article <>,
> Keith Thompson <kst-> wrote:
>> I admit that having (void*)0 and (void*)zero yield different values is
>> counterintuitive, but so is the whole idea of C's null pointer
>> constants IMHO. C's definition of a null pointer constant is so
>> narrow that I think it has to allow for this possibility.
>
> Null pointer constants are not very counter-intuitive really. All that
> the C Standard says is that in some cases, when you write 0 in a
> program, you actually get for example (char *) 0. There are similar
> situations: If a is an array, then in many situations where you write a,
> you actually get &a[0]. Or if you declare a function parameter as an
> array, like in int f (int a[10]); you actually get a pointer like int f
> (int* a).
Whether something is counterintuitive or not is bound to be a matter
of opinion. I won't say you're wrong, but I will say that my opinion
is unchanged. If it it were only the integer literal 0 that's
overloaded as a null pointer constant, it wouldn't be so bad, but the
standard requires 0, '\0', 0UL, ('/'/'/'-'/'/'/'), and (3/4) to be
treated as null pointer constants as well (probably so compilers can
perform constant-folding but don't have to remember they've done it),
but *doesn't* require a non-constant integer value of 0 to yield a
null pointer value when converted (at least, I don't *think* it does;
there's still some debate on that point). It leads too many people to
assume that a null pointer *value* is represented as all-bits-zero
(which isn't an entirely unreasonable assumption given that
integer-to-pointer conversion usually just reinterprets the bits), or
at least that pointers are really just integers.
Just look at the time we spend discussing it here, and how much room
it takes up in the FAQ. And think how much of this we could have
avoided if the original C had added a keyword "nil" and made it the
*only* valid null pointer constant.
If you find all that stuff intuitive, you have better (or more C-like)
intuition than I do.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.