Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 21 Aug 2002 00:31:12 -0600 (MDT)
From:      "M. Warner Losh" <imp@bsdimp.com>
To:        archie@dellroad.org
Cc:        freebsd-arch@FreeBSD.ORG
Subject:   Re: NULL
Message-ID:  <20020821.003112.86889670.imp@bsdimp.com>
In-Reply-To: <200208210140.g7L1eCJ03992@arch20m.dellroad.org>
References:  <20020821012849.GK3751@elvis.mu.org> <200208210140.g7L1eCJ03992@arch20m.dellroad.org>

next in thread | previous in thread | raw e-mail | index | archive | help
In message: <200208210140.g7L1eCJ03992@arch20m.dellroad.org>
            Archie Cobbs <archie@dellroad.org> 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 <locale.h>
       7.17  Common definitions <stddef.h>
       7.19  Input/output <stdio.h>
       7.20  General utilities <stdlib.h>
       7.21  String handling <string.h>
       7.23  Date and time <time.h>
       7.24  Extended multibyte and wide-character utilities <wchar.h>

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 <stddef.h> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020821.003112.86889670.imp>