I've been writing C++ for many years, using nullptr
for null pointers. I also know C, whence NULL originates, and remember that it's the constant for a null pointer, with type void *
.
For reasons, I've had to use NULL
in my C++ code for something. Well, imagine my surprise when during some template argument deduction the compiler tells me that my NULL is really a ... long. So, I double-checked:
#include <type_traits>
#include <cstddef>
static_assert(not std::is_same<decltype(NULL), long>::value, "NULL is long ???");
And indeed, the static assertion fails (with GCC and with Clang).
I checked on cppreference.com, and sure enough (C++11 wording):
The macro NULL is an implementation-defined null pointer constant, which may be an integer literal with value zero, or a prvalue of type
std::nullptr_t
.
Why does this make sense? In itself, and in light of the incompatibility of C?
void *
? – AlvyNULL
in C is just folklore, that is part of the truth. – Merete