🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #74641

Re: using 0 instead of NULL

#74641
From: Barry Margolin
Date: Sat, 09 Mar 1991 09:02
37 lines
2066 bytes
In article <1991Mar8.171015.2767@uvm.edu> wollman@emily.uvm.edu (Garrett Wollman) writes:
>In <lots of articles>, <lots of people> state that under C, the
>compiler must (In W. Losh's words) "do the right thing" when either 0
>or NULL is used.  This is FALSE.

Not "the right thing", but the *same* thing.

>extern void func_foo();
>
>void main() {
>	/* this */
>	func_foo("banana",0);
>	/* is NOT guaranteed to work as this */
>	func_foo("grape",(char *)0);
>	/* is */
>}
>
>Since most GNU software does not use prototypes, this is a valid
>objection, and one reason why I feel the GNU Coding Standards are an
>abomination.

Using NULL instead of 0 in the above example doesn't fix the bug, since
implementations are permitted to do "#define NULL 0".  In the absence of
prototypes, both NULL and 0 must be cast when being passed to a function
expecting a pointer.

Also, if the function is expecting a pointer type other than char* or
void*, even "#define NULL ((void*)0)" isn't enough to avoid the cast.
Different pointer types may have different representations (e.g.
word-oriented machines may use a less efficient representation for char*
and void* than for int*).  The cast is necessary to make sure that the
void* is converted to the appropriate parameter type.
--
Barry Margolin, Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar
Technical Details
Message-ID: <1991Mar9.090240.24204@Think.COM>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!spool.mu.edu!think.com!barmar
References: <27D16AC5.3952@maccs.dcss.mcmaster.ca> <1991Mar6.201539.17401@Solbourne.COM> <1991Mar8.171015.2767@uvm.edu>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1025b4,343b7ce3977dbb95
X-Google-Attributes: gid1025b4,public
X-Google-ArrivalTime: 1991-03-09 01:13:08 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!spool.mu.edu!think.com!barmar
From: barmar@think.com (Barry Margolin)
Newsgroups: gnu.misc.discuss
Subject: Re: using 0 instead of NULL
Message-ID: <1991Mar9.090240.24204@Think.COM>
Date: 9 Mar 91 09:02:40 GMT
References: <27D16AC5.3952@maccs.dcss.mcmaster.ca> <1991Mar6.201539.17401@Solbourne.COM> <1991Mar8.171015.2767@uvm.edu>
Sender: news@Think.COM
Organization: Thinking Machines Corporation, Cambridge MA, USA
Lines: 37
Posted: Sat Mar  9 03:02:40 1991