From owner-freebsd-standards@FreeBSD.ORG Sat Apr 12 23:30:13 2003 Return-Path: Delivered-To: freebsd-standards@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 4CD5E37B401 for ; Sat, 12 Apr 2003 23:30:13 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5C79E43FCB for ; Sat, 12 Apr 2003 23:30:12 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h3D6UCUp059110 for ; Sat, 12 Apr 2003 23:30:12 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h3D6UCBM059109; Sat, 12 Apr 2003 23:30:12 -0700 (PDT) Resent-Date: Sat, 12 Apr 2003 23:30:12 -0700 (PDT) Resent-Message-Id: <200304130630.h3D6UCBM059109@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-standards@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, "lamer." Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7505037B401 for ; Sat, 12 Apr 2003 23:21:42 -0700 (PDT) Received: from velocity.beatit.no (velocity.beatit.no [212.20.196.86]) by mx1.FreeBSD.org (Postfix) with SMTP id 9C97643F85 for ; Sat, 12 Apr 2003 23:21:40 -0700 (PDT) (envelope-from lamer@properfucked.net) Received: (qmail 17609 invoked from network); 13 Apr 2003 06:21:37 -0000 Received: from ti500720a080-1655.bb.online.no (HELO nynaeve.telaranrhiod) (@80.213.70.119) by velocity.beatit.no with SMTP; 13 Apr 2003 06:21:37 -0000 Message-Id: <20030413080947.B43406-100000@nynaeve.telaranrhiod> Date: Sun, 13 Apr 2003 08:22:07 +0200 (CEST) From: "lamer." To: FreeBSD-gnats-submit@FreeBSD.org Subject: standards/50889: NULL defined as 0 instead of (void *)0 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 13 Apr 2003 06:30:13 -0000 >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@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 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: