The C language requires that the short-circuiting operators ||
and &&
process their operands from left to right. So it will always evaluate the left operand, but the right operand will be evaluated conditionally. For ||
it evaluates the right operand if the left operand is false. For &&
it oevaluates the right operand if the left operand is true.
So order definitely matters. function() || A == B
calls the function. If it returns false, it will then test A == B
. But A == B || function()
first tests A == B
, and only calls the function if they're not equal.
This is not specific to GCC, it's part of the language specification (and it's similar in many other languages). It's also not related to if
, since you can use logical operators anywhere that an expression is allowed, e.g.
int foo = function() || A==B;