From owner-freebsd-arch Tue Aug 20 23:31:56 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 89FC737B400 for ; Tue, 20 Aug 2002 23:31:52 -0700 (PDT) Received: from harmony.village.org (rover.bsdimp.com [204.144.255.66]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8BCF643E75 for ; Tue, 20 Aug 2002 23:31:51 -0700 (PDT) (envelope-from imp@bsdimp.com) Received: from localhost (warner@rover2.village.org [10.0.0.1]) by harmony.village.org (8.12.3/8.12.3) with ESMTP id g7L6VmFl020993; Wed, 21 Aug 2002 00:31:48 -0600 (MDT) (envelope-from imp@bsdimp.com) Date: Wed, 21 Aug 2002 00:31:12 -0600 (MDT) Message-Id: <20020821.003112.86889670.imp@bsdimp.com> To: archie@dellroad.org Cc: freebsd-arch@FreeBSD.ORG Subject: Re: NULL From: "M. Warner Losh" In-Reply-To: <200208210140.g7L1eCJ03992@arch20m.dellroad.org> References: <20020821012849.GK3751@elvis.mu.org> <200208210140.g7L1eCJ03992@arch20m.dellroad.org> X-Mailer: Mew version 2.1 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message: <200208210140.g7L1eCJ03992@arch20m.dellroad.org> Archie Cobbs writes: : Are you saying that POSIX declares that NULL be "0"? Then I agree : we must do that.. but why then doesn't Linux? ISO-C99 says that '#define NULL 0' is standards compliant. Looks like (void *) 0 is also legal in 'C' for NULL (per 6.3.2.1.#3). NULL is *A* null pointer constant, and both '0' and '(void *) 0' are null pointer constants. However, for C++ NULL must be 0. It can't be (void *) 0 because int *a = NULL; would break and people expect that to work. We have to define NULL in 7 headers: 7.11 Localization 7.17 Common definitions 7.19 Input/output 7.20 General utilities 7.21 String handling 7.23 Date and time 7.24 Extended multibyte and wide-character utilities We could find _BSD_NULL_ the same place we define _BSD_SIZE_T_ and then define NULL to _BSD_NULL_, but that sounds like overkill to me. From the C-99 draft standard: 6.3.2.1 #3: [#3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.46) If a null pointer constant is assigned to or compared for equality to a pointer, the constant is converted to a pointer of that type. Such a pointer, called a null pointer, is guaranteed to compare unequal to a pointer to any object or function. 46)The macro NULL is defined in as a null pointer constant; see 7.17. ... K.3 Implementation-defined behavior [#1] A conforming implementation shall document its choice of behavior in each of the areas listed in this subclause. The following are implementation-defined: ... -- The null pointer constant to which the macro NULL expands (7.17). Warner To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message