EDIT: Found duplicate once I learned the term for this behaviour. Close as duplicate please.
Consider this
Class* p = NULL;
if( p != NULL && p->Method() == OK ){
// stuff
}
On all compilers I've worked with, this is quite safe. I.e. the first part of the boolean expression will evaluate to false, and the call to Method() will thus not be attempted since evaluating the second part is redundant.
Is this because most compilers will optimize away the evaluation of the second part, or is it a dictated behavior from the C/C++ standards?
EDIT: Found duplicate once I learned the term for this behaviour. Close as duplicate please.