In C++, if you have a pointer type and want to do a nullptr
check to make sure that the pointer is valid, is it safe to include other checks in the same if
statement that include the pointer that is being checked?
For example:
Control* c = nullptr;
if (c && c->is_view())
{
// do stuff
}
The pointer c
is being checked to see if it is nullptr
, but in the same conditional statement the is_view()
function is being called on the c
pointer. The call to is_view()
assumes that the pointer is valid.
Is this code safe?