Why is null lowercase?

monarch_dodra monarchdodra at gmail.com
Thu Jan 24 05:34:01 PST 2013


On Thursday, 24 January 2013 at 12:56:03 UTC, Matthew Caron wrote:
> This is probably a question for Walter, but maybe others know.
>
> Of all of the differences between C and D, the one which I have 
> the most difficulty adapting to is null being lowercase. Does 
> anyone know why this decision was made?

Keep in mind that strictly speeking, "NULL" != "null":

NULL is a C macro that expands to 0.
null is a D keyword that cannot be implicitly cast to an integer.

This is a source of bugs:

//----
void foo(int);
void foo(int*);
//----

in C++:
foo(NULL); //Calls "void foo(int)"

in D:
foo(null); //Calls "void foo(int*)"

Having code that is valid in both C++ and D, but having a 
different behavior would be VERY bad.

--------
BTW, you can be thankful that it is *just* "null", because what 
it really is C++11's "null_ptr". Which is worst.


More information about the Digitalmars-d-learn mailing list