hi all,
if I have:
if(A && B || C)
which operation gets executed first?
If I remeber well should be &&, am I correct?
thanks
Ivan
Assuming you meant by "operation" the "&&" and "||" operators, the C
answer is the "&&" operator gets evaluated first.
But that's not the right answer, because I don't know that you meant
that, and others reading your code might not know that you meant that,
or even know that's that the C answer.
The correct answer, in order to appease us all sitting here at the
round table, is that you must use parenthesis around the appropriate
pair of binary operands. Pick either (A && B) or (B || C). During the
code review we'll tell you if you're right or wrong. And most likely,
even before that, you'll know whether you're right or wrong.
C lets you get away with a lot of stuff. That doesn't mean you should
necessarily take the freedom to get away with said stuff.
Some organizations, such as MISRA (which deals in part with
safety-critical software), take such "stuff" very seriously, and
impose rules about what you can and cannot do in C. Many of the rules
are, IMHO, seriously worth considering in any type of software.