From owner-freebsd-hackers Fri Feb 14 17:15:51 1997 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.5/8.8.5) id RAA17850 for hackers-outgoing; Fri, 14 Feb 1997 17:15:51 -0800 (PST) Received: from nic.follonett.no (nic.follonett.no [194.198.43.10]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id RAA17838 for ; Fri, 14 Feb 1997 17:15:45 -0800 (PST) Received: (from uucp@localhost) by nic.follonett.no (8.8.5/8.8.3) with UUCP id CAA18492; Sat, 15 Feb 1997 02:13:26 +0100 (MET) Received: from oo7 (oo7.dimaga.com [192.0.0.65]) by dimaga.com (8.7.5/8.7.2) with SMTP id BAA19601; Sat, 15 Feb 1997 01:48:56 +0100 (MET) Message-Id: <3.0.32.19970215014856.00c14100@dimaga.com> X-Sender: eivind@dimaga.com X-Mailer: Windows Eudora Pro Version 3.0 (32) Date: Sat, 15 Feb 1997 01:48:58 +0100 To: Giles Lean From: Eivind Eklund Subject: Re: NULL as ((void*)0) (was Re: strlen() question) Cc: hackers@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Sender: owner-hackers@freebsd.org X-Loop: FreeBSD.org Precedence: bulk At 10:17 AM 2/15/97 +1100, Giles Lean wrote: >On Fri, 14 Feb 1997 17:36:53 +0100 Eivind Eklund wrote: > >> I hereby propose changing the default declaration of NULL under FreeBSD from >> #define NULL 0 >> to >> #define NULL ((void*)0) > >This is more of a kludge than a good idea, and I offer the following >sage advice that I filed away many years ago. Which I throughly agree with; it also come from people I defineatly respect. However, I don't feel that it disagree with the above proposition. [From Henry Spencer, of "10 commandments for C programmers" and regexp fame] >In any case, this stuff is a concession to badly-written code. No >properly-written code under ANSI compilers will notice the difference >between the different forms of NULL. In contexts where the desired >type is not known from context -- basically, function arguments in >the absence of a prototype or the presence of varargs -- NULL *must* >be cast to the proper pointer type. Having NULL ((void*)0) is a combination of a concession to badly written code (it makes it work on more machines, though not all) as well as a way of forcing people to avoid using NULL in non-pointer expressions. IMHO, a good thing. (If nobody else feel the same way I won't make any cahnges, of course.) BTW: I just got another idea - if we can turn the definition of NULL between ((void*)0) and 0 we can detect if NULL is abused if compiling on a machine with different sizeof(void*) and sizeof(int). If used correctly, code will be equal no matter what the definition - if used incorrectly, different code should result. This can provide fairly automatic detection of errors, provided we have two different builds. Eivind Eklund perhaps@yes.no http://maybe.yes.no/perhaps/ eivind@freebsd.org