C++ definition of NULL
Martin v. Loewis
martin@mira.isdn.cs.tu-berlin.de
Wed Mar 3 07:28:00 GMT 1999
> On the other hand, using NULL as the null pointer is sanctioned
> by common sense, tradition, helps code readability, and (using
> some name or other) is what every other high-level language
> providing pointers does.
>
> The C++ committee blew this one.
It seems we disagree. If the committee wanted to introduce a reserved
name for the null pointer constant, NULL definitely would have been a
bad choice, because people have all kinds of views what NULL is
(including (void*)0 and (char*)0). Also, people just *know* that NULL
is a macro. The way NULL is defined really reflects all this confusing
tradition, and is a bad start for defining a clean concept of 'null
pointer'.
I'm not sure how much readability is lost in a language if the null
pointer constant is removed. I found that people typically understand
very quickly that the right way to express a null pointer is to write
'0'. This is especially true since this constant needs all kinds of
funny polymorphic properties. Explaining that a conversion is going on
to the specific type required is much easier when you see that you
start off with a number literal.
Regards,
Martin
More information about the Gcc
mailing list