standards/50889: NULL defined as 0 instead of (void *)0
lamer.
lamer at properfucked.net
Sat Apr 12 23:30:13 PDT 2003
>Number: 50889
>Category: standards
>Synopsis: NULL defined as 0 instead of (void *)0
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Sat Apr 12 23:30:11 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator: Frank.
>Release: FreeBSD 4.7-RELEASE i386
>Organization:
None.
>Environment:
System: FreeBSD nynaeve.telaranrhiod 4.7-RELEASE FreeBSD 4.7-RELEASE #3: Mon Dec 9 19:44:33
CET 2002 root at nynaeve.telaranrhiod:/usr/src/sys/compile/NYNAEVE i386
>Description:
In the assorted standard headerfiles ({stdlib,stdio,unistd,time,string}.h
etc.) the NULL pointer constant seems to be defined as 0. Though this
works fine in most cases, it "breaks" on code using NULL as the right
operand with the comma operator as C99 (and C89) explicitly states that a
constant expression shall not contain comma operators.
So something like void *p = ((void)0, 0); is not strictly valid because 0
can only be interpreted as the null pointer constant when it is the
result of an integer constant expression.
Thus, to define NULL as simply 0, gives a warning (with strictly
conforming C compilers atleast) on code like "return whatever, NULL;"
Defining NULL as (void *)0 will make it a more generally usable macro as
the comma expression will retain the (void *) type of its right operand.
:)
Ref.: 6.6.3 of ISO/IEC 9899:1999(E) (no idea about the paragraph numbers
with C89).
>How-To-Repeat:
#include <stdio.h>
void *gah() { return (void)0, NULL; }
void *pah() { return puts("go."), NULL; }
etc.
If using GCC, compile with -pedantic for a warning to show on the gah()
function (this may be considered as a GNU extension).
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list