NULL is an implementation-defined macro that are consider problematic practice in C++.
Overloading
int f(int);
int f(int*);
f(NULL); // ambiguousWorse:
int g(long);
int g(long*);
g(NULL); // guess who get called?Optimization
A nullptr_t overload can be slightly fast than a pointer overload if we know a pointer is NULL at compile time.
nullptr In C
- The proposal: http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2394.pdf
- related: Type-generic macro
- “Conditional expressions such as
(1 ? 0 : NULL)and(1 ? 1 : NULL)have different status depending howNULLis defined. Whereas the first is always defined, the second is a constraint violation ifNULLhas typevoid*, and defined otherwise” - “A
NULLargument that is passed to ava_argfunction that expects a pointer can have severe consequences. On many architectures nowadaysintandvoid*have different size, and so ifNULLis just0, a wrongly sized arguments is passed to the function.”