Subject: Re: sys/null.h
To: Roland Illig <firstname.lastname@example.org>
From: Greg A. Woods <email@example.com>
Date: 04/15/2005 15:51:46
[ On Wednesday, April 13, 2005 at 18:09:32 (+0200), Roland Illig wrote: ]
> Subject: sys/null.h
> * What happens on I32LP64 systems?
> fprintf(stderr, "%#p %#p\n", NULL, NULL, 1, 2, 3, 4);
> I would expect the answer to not be "0x0 0x0".
You forgot the _necessary_ parameter casts.
Just because you're using C with prototypes doesn't mean you can get
away without casting some parameters to varargs/stdargs functions.
In fact when you use "%p" you really should always cast the relevant
parameter using "(void *)", even if it is already some other type of
pointer because "%p" is only defined for pointers to "void" objects.
Besides, portable code _MUST_ acknowledge that NULL may be defined as
the plain integer value zero.
> * Why don't we always #define NULL ((void *) 0) ?
Sane use of NULL in C does not require it to be anything but a plain
integer zero, and indeed anything else can cause far more headaches and
confusion than is necessary since NULL gets used in real code in many
places where a pointer type is not desired. (Maybe it shouldn't be, but
that's the way it is; and the standard doesn't really preclude the use
of the NULL macro in many of the places were a pointer type is not
> (We don't have to be pre-ANSI compatible anyway.)
Yes, NetBSD _MUST_ be able to compile both pre-ANSI code and code that
uses NULL as an int or char value thus the public headers really must
use a plain integer zero for NULL.
Greg A. Woods
H:+1 416 218-0098 W:+1 416 489-5852 x122 VE3TCP RoboHack <firstname.lastname@example.org>
Planix, Inc. <email@example.com> Secrets of the Weird <firstname.lastname@example.org>