Path: utzoo!mnetor!uunet!lll-winken!lll-lcc!ames!necntc!linus!philabs!micomvax!ray From: ray@micomvax.UUCP (Ray Dunn) Newsgroups: comp.lang.c Subject: Re: Why NULL is 0 Message-ID: <963@micomvax.UUCP> Date: 30 Mar 88 00:41:21 GMT References: <2550049@hpisod2.HP.COM> <7412@brl-smoke.ARPA> <3351@chinet.UUCP> <10574@mimsy.UUCP> <10576@mimsy.UUCP> <636@acer.stl.stc.co.uk> Reply-To: ray@micomvax.UUCP (Ray Dunn) Organization: Philips Electronics Ltd. (TDS - Montreal) St. Laurent P.Q., Canada Lines: 37 Summary: In article <10576@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: > > [the definitive, correct explanation of NULL and pointers] > In article <636@acer.stl.stc.co.uk> scott@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