From owner-freebsd-hackers Fri Feb 14 15:50:42 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id PAA12006 for hackers-outgoing; Fri, 14 Feb 1997 15:50:42 -0800 (PST) Received: from sax.sax.de (sax.sax.de [193.175.26.33]) by freefall.freebsd.org (8.8.5/8.8.5) with SMTP id PAA11998 for ; Fri, 14 Feb 1997 15:50:36 -0800 (PST) Received: (from uucp@localhost) by sax.sax.de (8.6.12/8.6.12-s1) with UUCP id AAA08044 for hackers@FreeBSD.ORG; Sat, 15 Feb 1997 00:50:30 +0100 Received: (from j@localhost) by uriah.heep.sax.de (8.8.5/8.6.9) id AAA12291; Sat, 15 Feb 1997 00:26:27 +0100 (MET) Message-ID: Date: Sat, 15 Feb 1997 00:26:27 +0100 From: j@uriah.heep.sax.de (J Wunsch) To: hackers@FreeBSD.ORG Subject: Re: NULL as ((void*)0) (was Re: strlen() question) References: <3.0.32.19970214173652.00c0b290@dimaga.com> X-Mailer: Mutt 0.55-PL10 Mime-Version: 1.0 X-Phone: +49-351-2012 669 X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F 93 21 E0 7D F9 12 D6 4E Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch) In-Reply-To: <3.0.32.19970214173652.00c0b290@dimaga.com>; from Eivind Eklund on Feb 14, 1997 17:36:53 +0100 Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk As Eivind Eklund wrote: > I hereby propose changing the default declaration of NULL under FreeBSD from > #define NULL 0 > to > #define NULL ((void*)0) > for better type-safety and ease of transition to other architechtures > (e.g. Alpha). This will probably save us from a quite a few varargs-voes, > as well as generally making sure the code-base is using NULL correctly, > which is important for those reading source-code. Nope, it wouldn't get you anywhere. The vararg-woes cannot be solved by it either, since you gotta cast to the exact type in any case anyway. Passing (void *)0 into a vararg list is as invalid as passing 0 there if the target type is e.g. char *. It wouldn't ensure the code base is using NULL everywhere either, since assigning 0 to a pointer is valid (and sometimes [e.g. GNU] even encouraged) C code. Inside a function call, you only need to cast it into the correct target type if: 1) it's in a vararg list, or 2) it's in an arg list of a function declared with obsolete K&R style only. See also the comp.lang.c FAQ. The only reason to use NULL is to make it more obvious to the reader that you're thinking of a pointer context. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-)