This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: C++ definition of NULL
- To: "Gabriel Dos Reis" <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>, "Alexandre Oliva" <oliva at dcc dot unicamp dot br>
- Subject: Re: C++ definition of NULL
- From: "Doug Semler" <doug at seaspace dot com>
- Date: Wed, 3 Mar 1999 11:07:15 -0800
- Cc: "Chad Gatesman" <chadg at redrose dot net>, "Jason Merrill" <jason at cygnus dot com>, <egcs at cygnus dot com>
----- Original Message -----
From: Alexandre Oliva <oliva@dcc.unicamp.br>
To: Gabriel Dos Reis <Gabriel.Dos-Reis@dptmaths.ens-cachan.fr>
Cc: Doug Semler <doug@seaspace.com>; Chad Gatesman <chadg@redrose.net>;
Jason Merrill <jason@cygnus.com>; <egcs@cygnus.com>
Sent: Tuesday, March 02, 1999 11:37 PM
Subject: Re: C++ definition of NULL
>On Mar 3, 1999, Gabriel Dos Reis <Gabriel.Dos-Reis@dptmaths.ens-cachan.fr>
wrote:
>
>> NULL is *not* a pointer. NULL is _convertible_ to pointer type. More
>> explicitly, the C++ Standard says:
>
>> 4.10/1
>> ---
>> A null pointer constant is na integral expression (5.19) rvalue of
>> integer type that evaluates to zero.
>> ---
Damn, this one section is confusing....the way I've always read it is that
NULL is a macro to a null pointer constant (18.1.4) (which may be 0
or 0L)
A Null pointer constant is a constant rvalue integral *expression* which
evaluates to 0.
The Null pointer value (the value of the expression) can be converted to a
cv-qualified type.
The conversion from the expression is one
step. So any constant integral rvalue of 0 can be a null pointer constant.
So the way I read the standard, the type of a null pointer constant is
a pointer type of pointer to destination's cv-qualified type.
eg:
int *a = NULL ; // NULL has type int *
int a = NULL; // Error: cannot implicitly convert pointer type to int
Right?????
>
>> So NULL is of integer type. Exactly wich one is implementation-defined.
>
>Actually, it needs not be an integer type; the definition
>
>enum __NULL_type { __null = 0 };
>#define NULL __null
>
>is a valid one, because integral expressions may involve enumerators.