Skip site navigation (1)Skip section navigation (2)
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)
Message-ID:  <Mutt.19970215002627.j@uriah.heep.sax.de>
In-Reply-To: <3.0.32.19970214173652.00c0b290@dimaga.com>; from Eivind Eklund on Feb 14, 1997 17:36:53 %2B0100
References:  <3.0.32.19970214173652.00c0b290@dimaga.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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. ;-)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Mutt.19970215002627.j>