i always make code like this:Quote:
Originally Posted by TheCPUWizard
i dont think its any diffrent..Code:if (ptr)
if(ptr->MethodIO)
{
}
however the evaluation stops at ptr, is this defined behavior by the standards?
Printable View
i always make code like this:Quote:
Originally Posted by TheCPUWizard
i dont think its any diffrent..Code:if (ptr)
if(ptr->MethodIO)
{
}
however the evaluation stops at ptr, is this defined behavior by the standards?
The standard guarantees that the right-hand-side of && will not be evaluated if the left-hand side of && is false. Also the right-hand-side of || will not be evaluated if the left-hand side of && is true.
But if && or || is overloaded, that guarantee is lost because both sides need to be evaluated before operator&& or operator|| can be called, I think.
the link provided by exterminator explain one more factor, a++ and ++a can be evaluated at the same time, which can mess up the memory. :ehh: so maybe undefined behavior will be more correct than unspecified behavior.Quote:
Originally Posted by exterminator
Thanks!
Yes, it is.Quote:
Originally Posted by Mitsukai
&& also is a sequence point.Code:5.14 Logical AND operator [expr.log.and]
logical-and-expression:
inclusive-or-expression
logical-and-expression && inclusive-or-expression
1 The && operator groups left-to-right. The operands are both implicitly
converted to type bool (clause 4). The result is true if both operands are
true and false otherwise. Unlike &, && guarantees left-to-right evaluation:
the second operand is not evaluated if the first operand is false.
2 The result is a bool. All side effects of the first expression except for
destruction of temporaries (12.2) happen before the second expression is evaluated.