c++ - Can a preexisting return of a typecast NULL be safely compared to a newer nullptr? -
i required use library written before c++11, , 1 of functions can return typecast null. i'm trying write program following c++11 standards, when protecting against null reference, use like:
if(retptr==nullptr){...}
is safe comparison? arguments sake between (int*)null , (int*)nullptr? or should use an:
if(retptr){...}?
can preexisting return of typecast
null
safely compared newernullptr
?
yes. cppreference.com:
there exist implicit conversions
nullptr
null pointer value of pointer type , pointer member type. similar conversions exist value of typestd::nullptr_t
macronull
, null pointer constant.
as praetorian kindly pointed out, corresponding section of standard 4.10 [conv.ptr].
see what nullptr?
Comments
Post a Comment