Keywords: ISO C++ , library

NULL
Prev | Chapter 4. Types | Next

## NULL

The only change that might affect people is the type of `NULL`: while it is required to be a macro, the definition of that macro is not allowed to be `(void*)0`, which is often used in C.

For g++, `NULL` is

    #define

'd to be `__null`, a magic keyword extension of g++.

The biggest problem of #defining `NULL` to be something like “0L” is that the compiler will view that as a long integer before it views it as a pointer, so overloading won't do what you expect. (This is why g++ has a magic extension, so that `NULL` is always a pointer.)

In his book Effective C++, Scott Meyers points out that the best way to solve this problem is to not overload on pointer-vs-integer types to begin with. He also offers a way to make your own magic `NULL` that will match pointers before it matches integers.

See the Effective C++ CD example

Prev | Up | Next
Numeric Properties | Home | Chapter 5. Dynamic Memory