I'm staring at the following expression, written by someone else:
if (variableA == CaseA && GetCase(variableB) == CaseA && GetCase(variableC) == CaseA && !CaseB(variableB) || variableA != CaseA)
{
// do stuff
}
What's really tripping me up is this bit:
!CaseB(variableB) || variableA != CaseA
Because there aren't any parentheses to group the conditionals together.
How will the C++ compiler evaluate these if statements? If one of the AND operators evaluates to false, does this mean that the OR won't be checked due to short circuit?
Edit
Wow, I guess the haters really want to hate today, considering the amount of downvotes for each answer in addition to the -4 (and counting?) for the question. And, uh, no actual explanation for why? Lol.
Stay classy, people. Stay classy. ;)
For the record, simply stating that there's a "left to right evaluation" doesn't really say much in terms of providing a valid answer for the question. I actually did use the great power of Google (which also lead to a few posts here that I read) before posting.
I'll admit my mistake here was failing to mention that, and while I think that the C++ reference is the most natural link to post as a supplement for an answer, the best information I was able to get was inadvertently from here, via the following quote in a source code example:
|| has lower precedence than &&
Which is arguably vague, because "lower precedence" isn't actually specified in terms of what that means in this context.
Either way, to those who actually contributed you will receive an upvote - I'm going to accept the answer which gave me what I was really looking for.
The expression is equivalent to:
( (variableA == CaseA) &&
(GetCase(variableB) == CaseA) &&
(GetCase(variableC) == CaseA) &&
(!CaseB(variableB))
)
||
(variableA != CaseA)
The expression will be evaluated from the top down (because of the short circuit rules), and if any of the first four lines return false, none of the remain first four lines will be evaluated. If (and only if) one of the first four lines return false, then the final line will be evaluated.
But I am interested that the last line is the negation of the first