Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 28 May 1998 18:19:30 +0200
From:      Eivind Eklund <eivind@yes.no>
To:        =?iso-8859-1?Q?Dag-Erling_Coidan_Sm=F8rgrav?= <dag-erli@ifi.uio.no>
Cc:        current@FreeBSD.ORG
Subject:   Re: Replacing gcc as the system compiler
Message-ID:  <19980528181930.06204@follo.net>
In-Reply-To: =?iso-8859-1?Q?=3Cxzpra1ecu9h=2Efsf=40gjallarhorn=2Eifi=2Euio=2Eno=3E=3B?= =?iso-8859-1?Q?_from_Dag-Erling_Coidan_Sm=F8rgrav__on_Thu=2C_May_28=2C_1?= =?iso-8859-1?Q?998_at_05=3A03=3A38PM_%2B0200?=
References:  <199805280348.NAA09679@godzilla.zeta.org.au> <xzpra1ecu9h.fsf@gjallarhorn.ifi.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, May 28, 1998 at 05:03:38PM +0200, Dag-Erling Coidan Smørgrav  wrote:
> Bruce Evans <bde@zeta.org.au> writes:
> > > There is also what looks like a bug in handling of NULL - it doesn't
> > > allow the use of ((void *)0) as NULL for function pointers.
> > gcc used to have this bug too.  Apparently, the C standard can easily
> > be read as not allowing conversion from (void *)0 to a function pointer.
> > The standard doesn't allow conversion from an object pointer to a
> > function pointer, but (void *)0 is is a null pointer constant and
> > null pointer constants are special.
> 
> The C null pointer constant is 0. No cast is needed. Converting 0 to a
> function pointer might work better than converting ((void *)0).

The C null pointer constant _can be_ 0.

Chapter and verse is (from the working draft, which is what I have
online): Section 6.2.2.3, item 3.

   3.  An integer constant expression with the value 0, or such an
       expression cast to type void *, is called a null pointer
       constant.[53] If a null pointer constant is assigned to or
       compared for equality to a pointer, the constant is converted
       to a pointer of that type.  Such a pointer, called a null
       pointer, is guaranteed to compare unequal to a pointer to any
       object or function.

If you read this carefully, you will see this carefully allow the use
of ((void*)0).

It also allow expressions like ((void*)(14L-2L*7U)), but they are of
somewhat dubious use - possibly useful for testing that the constant
elimination in your compiler is done as early as it is required to.

> The only situation in which it is advantageous to define NULL as
> ((void*)0) instead of just (0) is when passing NULL to a vararg
> function which lacks a prototype; but you shouldn't do that anyway,
> because it will break on more than just NULL (float->double conversion
> for instance)

It is of advantage when some retarded pseudo-programmer have left

	int i = NULL;

and other similar statements everywhere in the code and I want that to
break.

Eivind.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message



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