Possible Duplicate:
Is Short Circuit Evaluation guaranteed In C++ as it is in Java?
How does C++ handle &&? (Short-circuit evaluation)
I have the following struct definition and a particular use case:
struct foo
{
bool boo;
};
int main()
{
foo* f = 0;
.
.
.
if ((f) && (f->boo)) // <--- point of contention
return 0
else
return 1;
}
Does the standard guarantee that the first set of braces in the if-statement above will always be evaluated before the second?
If it doesn't what is the best what to rewrite the above bit of code?
Currently I have the following mess:
if (f)
{
if (f->boo)
return 0;
else
return 1;
}
else
return 1;