standards/50889: NULL defined as 0 instead of (void *)0

Erik Trulsson ertr1013 at student.uu.se
Wed Apr 16 10:27:28 PDT 2003


On Thu, Apr 17, 2003 at 01:00:40AM +1000, Bruce Evans wrote:
> On Wed, 16 Apr 2003, Erik Trulsson wrote:
> 
> > On Wed, Apr 16, 2003 at 05:49:55AM -0700, Jens Schweikhardt wrote:
> > > I agree, though, that it may be desirable to
> > > #define NULL ((void*)0)
> >
> > Unless you want to use the same definition for both C and C++.
> > In C++ the only valid way of defining NULL is
> >
> > #define NULL 0
> >
> > because in C++ there is no automatic conversion between "pointer to
> > void" and other pointer types as there is in C.
> 
> I agree.  It may be, and is, also desireable to define NULL as 0.
> A bit more desireable IMO.  Whichever detects the most bugs at compile
> time is best.

Yes, but the problem here is that each of the two definitions detects
some bugs but also hides some bugs. The bugs that are detected/hidden
are of course different between the two definitions.
Thus, there is not really any "best" definition and and which one
detects most bugs depends on what kind of bugs a program has.

Well written programs must be able to cope with either definition and
since both variants have their advantages and disadvantages it really
doesn't matter much which definition is used. They will both work about
equally well.
(Except that, as noted above, for C++ the only valid definition of NULL
is as 0, so if one wants to share the include files between C and C++
(and one probably wants to do that) and don't want to mess around with
#ifdefs to have different definitions for C and C++ (which seems a bit
pointless to me) there is not much choice on what definition to use.)




-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013 at student.uu.se


More information about the freebsd-standards mailing list