Comparing NULL and nullptr

Is it safe to compare pointers where one is NULL and the other is nullptr ? Will this comparison always be true?

+4
source share
2 answers

Yes.

Both NULLand nullptrare "null pointer constant" and

The null pointer constant can be converted to a pointer type; the result is a null pointer value of this type and is different from any other object pointer value or function pointer type.

Finally,

Two null pointer values ​​of the same type are compared equal.

(Both citations are 4.10 / 1 in N4140)

+5
source

, NULL 0 ( a #define, ), , .

+2

Source: https://habr.com/ru/post/1618654/


All Articles