if( (A) && (B) )
{
//do something
}
else
//do something else
The question is, would the statement immediately break to else if A was FALSE. Would B even get evaluated?
I ask this in the case that B checking the validity of an array index say array[0] when the array is actually empty and has zero elements. Therefore throwing a segfault because we are trying to access something that is out of bounds of the array. Specifically
if( (array.GetElements() > 0) && (array[0]))
array[0]->doSomething();
else
//do nothing and return
This may be dangerous if array[0] actually gets evaluated because it segfaults without the first check to the left of the '&&'. Precedence tells me that the left side will definitely take precedence but it doesn't tell me that it won't evaluate the right side if the left is FALSE.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…