From owner-freebsd-current Thu May 28 09:20:01 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id JAA05036 for freebsd-current-outgoing; Thu, 28 May 1998 09:20:01 -0700 (PDT) (envelope-from owner-freebsd-current@FreeBSD.ORG) Received: from ns1.yes.no (ns1.yes.no [195.119.24.10]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id JAA05008 for ; Thu, 28 May 1998 09:19:58 -0700 (PDT) (envelope-from eivind@bitbox.follo.net) Received: from bitbox.follo.net (bitbox.follo.net [195.204.143.218]) by ns1.yes.no (8.8.7/8.8.7) with ESMTP id QAA01183; Thu, 28 May 1998 16:19:51 GMT Received: (from eivind@localhost) by bitbox.follo.net (8.8.8/8.8.6) id SAA21845; Thu, 28 May 1998 18:19:39 +0200 (MET DST) Message-ID: <19980528181930.06204@follo.net> Date: Thu, 28 May 1998 18:19:30 +0200 From: Eivind Eklund To: =?iso-8859-1?Q?Dag-Erling_Coidan_Sm=F8rgrav?= Cc: current@FreeBSD.ORG Subject: Re: Replacing gcc as the system compiler References: <199805280348.NAA09679@godzilla.zeta.org.au> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Mailer: Mutt 0.89.1i 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_+0200?= Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Thu, May 28, 1998 at 05:03:38PM +0200, Dag-Erling Coidan Smørgrav wrote: > Bruce Evans 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