NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

standards/41890: NULL is improperly defined

>Number:         41890
>Category:       standards
>Synopsis:       NULL is improperly defined
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    standards-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Aug 14 12:40:00 +0000 2009
>Originator:     Eric Blake
>Release:        1.6
NetBSD netbsd 1.6 NetBSD 1.6 (GENERIC) #0: Sun Sep  8 19:43:40 UTC 2002

NetBSD's definition of NULL as '(void *)0' falls foul of the POSIX rule that 
object-like macros can be used in arbitrary expressions.  I have confirmed the 
bug on an older release (as that is the only NetBSD machine I have access to), 
but the problem apparently still exists in NetBSD 5.0, as documented here:

The fix is to use '#define NULL ((void *) 0)' in /usr/include/sys/null.h; by 
properly parenthesizing NULL, then arbitrary expressions like:

sizeof NULL

will no longer cause compile errors.

On the (older) machine that I have access to, I needed to define __AUDIT__ to 
expose the invalid definition of NULL; but apparently, newer NetBSD headers 
include the cast automatically (POSIX 2008 requires that NULL be defined with 
the cast to void*, so this is actually a good thing; it's just that you didn't 
go far enough by failing to properly parenthesize the result).

$ cat <<\EOF > foo.c
> #include <stddef.h>
> int main () { return sizeof NULL; }
$ c89 -o foo foo.c
$ c89 -D__AUDIT__=1 -o foo foo.c
foo.c: In function `main':
foo.c:2: parse error before `0'

Properly parenthesize the definition of NULL.

Home | Main Index | Thread Index | Old Index