We now have C++11 with many new features. An interesting and confusing one (at least for me) is the new nullptr
.
Well, no need anymore for the nasty mac
0 used to be the only integer value that could be used as a cast-free initializer for pointers: you can not initialize pointers with other integer values without a cast.
You can consider 0 as a consexpr singleton syntactically similar to an integer literal. It can initiate any pointer or integer. But surprisingly, you'll find that it has no distinct type: it is an int
. So how come 0 can initialize pointers and 1 cannot? A practical answer was we need a means of defining pointer null value and direct implicit conversion of int
to a pointer is error-prone. Thus 0 became a real freak weirdo beast out of the prehistoric era.
nullptr
was proposed to be a real singleton constexpr representation of null value to initialize pointers. It can not be used to directly initialize integers and eliminates ambiguities involved with defining NULL
in terms of 0. nullptr
could be defined as a library using std syntax but semantically looked to be a missing core component.
NULL
is now deprecated in favor of nullptr
, unless some library decides to define it as nullptr
.