I was wondering if NULL
is guaranteed to be 0
in C++, so I searched and came across these:
This answer states that:
Here is Bjarne Stroustrup's wordings,
In C++, the definition of NULL is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with NULL is that people sometimes mistakenly believe that it is different from 0 and/or not an integer.
Which seems to confirm that NULL
is always 0.
But according to cppreference.com:
#define NULL /*implementation-defined*/
The macro NULL is an implementation-defined null pointer constant, which may be:
-> an integral constant expression rvalue of integer type that evaluates to zero (until C++11)
-> an integer literal with value zero, or a prvalue of type std::nullptr_t (since C++11)
And that clearly says NULL
is implementation dependent.
This answer says:
0 (aka. C's NULL bridged over into C++) could cause ambiguity in overloaded function resolution, among other things:
f(int); f(foo *);
Which again implies that NULL
is the integer 0
and that might cause ambiguity
There are other questions and answers I encountered, but they are mostly about the C language, not C++. This comment says:
And NULL is guaranteed to be 0
But again, that's about C.
To sum it all up, is NULL
always 0
in C++? What about C? Is it (for every standard implementation) the same as:
#define NULL 0
Note: this question is not about the null pointer, the question is if NULL
in C++ is guaranteed to be 0
the integer. Is it implementation dependent?