Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!seismo!brl-tgr!tgr!bilbo.niket@locus.ucla.edu From: bilbo.niket@locus.ucla.edu (Niket K. Patwardhan) Newsgroups: net.lang.c Subject: Re: NULL pointer Message-ID: <3361@brl-tgr.ARPA> Date: Mon, 18-Nov-85 16:49:23 EST Article-I.D.: brl-tgr.3361 Posted: Mon Nov 18 16:49:23 1985 Date-Received: Wed, 20-Nov-85 00:59:34 EST Sender: news@brl-tgr.ARPA Lines: 66 >Date: Sun, 17 Nov 85 3:59:50 EST >From: Doug Gwyn (VLD/VMB) >To: Davidsen >cc: info-c@brl-tgr.arpa >Subject: Re: NULL pointer > >I'll see if I can beat Guy Harris to this one: > >The whole topic of the correct #definition for NULL >has been beat to death more than once on this mailing list. > >The answer is that NULL must be defined as simply 0 >and that code that misuses NULL cannot be fixed in >general by any change in its #definition. > >Consider > > hi_func() > { > ... > lo_func( ..., NULL, ... ); > ... > } > > lo_func( ..., p, ... ) > int *p; > { > ... > } > >This code is INCORRECT, whether NULL is #defined as 0 >or as (char *)0. The only correct way to do this >(not counting the new X3J11 parameter type coercion >mechanism) is to change the invocation of lo_func to: > > lo_func( ..., (int *)NULL, ... ); > >By trying to #define NULL as (char *)0, you are trying >to keep the programmer from having to understand this >and deal with it properly. You also cause problems >with statements such as > > if ( p == NULL ) > do_stuff; > >when the type of `p' is not (char *). The only >universal #definition for NULL that works in all such >cases is 0. (Of course, some machines allow sloppier >usage. This discussion assumes universality.) > >#define NULL 0 /* don't muck around with it */ The last line: ---- I agree with it whole-heartedly. But..... for a machine with non-zero null pointer representations > lo_func( ..., (int *)NULL, ... ); still doesn't work. What the callee routine gets is a pointer with an all-zero representation.... which isn't a null pointer. The ONLY thing that does work is lo_func( ..., p=0, ....); where p is a pointer of the requisite type! Of course, with parameter type coercion (or should I say conversion.. it isn't the same thing), this shouldn't be necessary!