c++ - Is it safe to have an invalid operation in the second half of && in an if statement? -
is safe:
if(sprite->numberofsides !=0 && sprite->value%sprite->numberofsides!=0) if sprite->numberofsides can == 0?
the reason ask, if frame if statement this:
if(sprite->value%sprite->numberofsides!=0 && sprite->numberofsides !=0) i exception (because can't n%0). reversing former statement works fine, don't want trouble down road when compiling different devices.
yes it's safe. short-circuiting guaranteed standard.
this means if first part of , (&&) expression evaluates false, it's guaranteed second part won't evaluated.
from c++03 - 5.14/1
the
&&operator groups left-to-right. [...] second operand not evaluated if first operandfalse.
Comments
Post a Comment