Why NULL is 0
Dave Sill
dsill at NSWC-OAS.arpa
Fri Mar 18 01:07:20 AEST 1988
I wrote:
>In article <800 at zippy.eecs.umich.edu> Jan Wolter <janc at palam.eecs.umich.EDU> writes:
>> char *p2 = zero; /* is this a null pointer? */
>
>Maybe. K&R say assignments between pointers and ints are nonportable,
>as are assignments between different types of pointers.
>
>> char *p3 = (char *)zero; /* what's this? */
>
>Exactly the same as p2. K&R define a cast as performing the
>conversions required to assign the operand to a variable of the type
>of the cast.
K&R page 42:
"... (type-name) expression ...
The precise meaning of a cast is in fact as if *expression* were
assigned to a variable of the specified type..."
This leads one to the conclusion that
char *p = zero;
and
char *p = (char *)zero;
give the same result. Why, then, does the former cause a warning
about an illegal combination of pointer and integer? Is the sole
function of the cast in the latter to prevent such a warning?
>>(Frankly,
>>the more I read on this subject, the more I think K&R didn't have their minds
>>entirely clear on this business either.)
>
>Maybe you should read some more.
I'd suggest reading the dpANS-C, where this is all much more
well-defined.
=========
The opinions expressed above are mine.
"Meanings receive their dignity from words instead of giving it to them."
-- Blaise Pascal
More information about the Comp.lang.c
mailing list