Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 14 Feb 1997 23:46:22 +0100
From:      Eivind Eklund <eivind@dimaga.com>
To:        "Arne H. Juul" <Arne.Juul@idt.ntnu.no>
Cc:        hackers@freebsd.org
Subject:   Re: NULL as ((void*)0) (was Re: strlen() question)
Message-ID:  <3.0.32.19970214234620.00b72540@dimaga.com>

next in thread | raw e-mail | index | archive | help
At 10:29 PM 2/14/97 +0100, Arne H. Juul wrote:
>[Eivind Eklund]
>> 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.
>
>This *shouldn't* help.  If it does, the code is broken.
>All code should do the right thing with varargs; if having NULL be
>plain 0 breaks it, so much the better :-)   Broken code should be
>found and fixed, not nurtured.

We presently cannot find it; and finding it all on the Alpha port could be
pretty ugly.  Besides, changing it to ((void*)0) will find as much broken
code as we can, fix that, and make the other closer to harmless.  (It will
break only on architectures where different pointers have different
internal structure, which are becoming rare.)

I still say we should go for it.

>Ideally one should define NULL to plain 0 sometimes, to
>(void *)0  sometimes, and to (1-1)  (or some other bizarre but
>legal option) sometimes, just to find bugs in the source tree.

Would be nice if there are some legal but bizarre options - unfortuneatly,
there isn't ((1-1) is illegal - integer type).  The following two (with
possibly added parantheses) are all there is:
#define NULL 0
#define NULL ((void*)0)

If I remember correctly, NULL should reduce to a single token - then
stripping parantheses from the second expression is technically incorrect.
(This might be an inconsistency in the standard - it does not seem to be
possible to produce a statement that give an error without parantheses but
work with.  However, the grammar conflict will come at different points.)



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.19970214234620.00b72540>