<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH] Use NULL in vararg



On Wed, 10 Nov 2004, Werner Koch wrote:

> On Wed, 10 Nov 2004 06:19:36 -0500 (EST), Thomas Dickey said:
>
> > iirc, it is C++ that adds a cast, while C doesn't.
>
> No. NULL needs to evaluate to a pointer value; thus the cast is
> required unless pointer and integer have the same size.

I agree that it should, and the given usage of it "needs" that
interpretation, but C doesn't do that (it is implied but not explicit in
C99, and different implementations may/may not actually apply a cast in
the definition).  Here's an example of how it is defined on Solaris (as
noted below, that belongs in stddef.h and is found there):

#ifndef NULL
#if defined(_LP64) && !defined(__cplusplus)
#define NULL    0L
#else
#define NULL    0
#endif
#endif

C99 states that NULL is defined as a pointer constant in stddef.h (7.17).
A literal zero is a valid pointer constant (6.3.2.3).

Given the overall bias of the mailing list - a quick check of glib
demonstrates that it doesn't define it there. grep shows that it is
defined in various headers, sometimes as 0 (for C++), sometimes with a
cast - I see three distinct flavors on my Debian/testing box (which
appears to be lacking stddef.h - hence it doesn't follow C99).

Perhaps you have some standard-conformant implementation in mind.

for the rest - I already knew that (but it probably is good exercise to
write it down ;-).

-- 
Thomas E. Dickey
http://invisible-island.net
ftp://invisible-island.net