Why NULL is 0

Ray Dunn ray at micomvax.UUCP
Wed Mar 30 10:41:21 AEST 1988


In article <10576 at mimsy.UUCP> chris at mimsy.UUCP (Chris Torek) writes:
>
> [the definitive, correct explanation of NULL and pointers]
>

In article <636 at acer.stl.stc.co.uk> scott at acer.UUCP (Mike Scott) totally
f*cks things up again by writing:
>
>If I could add my 2 pennyworth.  From K&R p192, we read " it is
>guaranteed that assignment of the constant 0 to a pointer will
                 ****************************
>produce a null pointer distinguishable from a pointer to any object".
>
>From page 71: "Within a function, each argument is in effect a local
>variable initialized to the value with which the function was called."
>
>It follows at once from these that the integer 0 may be supplied in
                                    *****************************
>any function call ......


Mike, is your slip showing clearly enough??

The compiler treats the *constant* zero specially, as being any required
number of bits to match the type of the pointer lvalue *in an assignment* -
i.e.  that syntactic thingamy which uses the "=" symbol!!!!

In other words, when ='ed to a pointer, the constant 0 is automatically
cast to the correct type.

In all other cases, 0 is just like any other int, constant or variable, and
must be cast to the correct type, as it occupies the number of bits defined
for ints in that implementation.

Everybody - *LISTEN* - Chris is *RIGHT* - don't write any other explanation
- read Chris' article again, and *LEARN*.

Ray Dunn.  ..{philabs,mnetor,musocs}!micomvax!ray



More information about the Comp.lang.c mailing list