The downside of NULL in C++ is that it is a define for 0. This is a value that can be silently converted to pointer, a bool value, a float/double, or an int.
That is not very type safe and has lead to actual bugs in an application I worked on.
Consider this:
void Foo(int i);
void Foo(Bar* b);
void Foo(bool b);
main()
{
Foo(0);
Foo(NULL); // same as Foo(0)
}
C++11 defines a nullptr
that is convertible to a null pointer but not to other scalars. This is supported in all modern C++ compilers, including VC++ as of 2008. In older versions of GCC there is a similar feature, but then it was called __null
.