Date: Sat, 15 Feb 1997 01:48:58 +0100 From: Eivind Eklund <eivind@dimaga.com> To: Giles Lean <giles@nemeton.com.au> Cc: hackers@freebsd.org Subject: Re: NULL as ((void*)0) (was Re: strlen() question) Message-ID: <3.0.32.19970215014856.00c14100@dimaga.com>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3.0.32.19970215014856.00c14100>