Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 16 Apr 2003 19:27:23 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        Jens Schweikhardt <schweikh@freebsd.org>
Subject:   Re: standards/50889: NULL defined as 0 instead of (void *)0
Message-ID:  <20030416172723.GA13575@falcon.midgard.homeip.net>
In-Reply-To: <20030417005708.D6167@gamplex.bde.org>
References:  <200304161249.h3GCntqZ071047@freefall.freebsd.org> <20030416125715.GA12300@falcon.midgard.homeip.net> <20030417005708.D6167@gamplex.bde.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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@student.uu.se



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030416172723.GA13575>