I have been trying to really master order of evaluation in complex expressions. As far as I can tell, the rules include operator precedence, operator associativity, left then right evaluation of binary operands, shortcut evaluation of certain logical operators, and ???
Is there a good write-up showing exactly how these rules play into each other?
Just as an example, && and < have lower precedence than ++, so why doesn't
(i < 4 && ++i > 4) always increment i before < and && are evaluated at all?
On the other hand,
int index = 4;
a[index] = index = index-2;
changes a[4], not a[2], so [] is evaluated before the operands of the right-hand =.
I can answer this stuff from a compiler (abstract syntax tree) perspective, but not from a language rules perspective.
Is there a good write-up showing exactly how these rules play into each other?
Just as an example, && and < have lower precedence than ++, so why doesn't
(i < 4 && ++i > 4) always increment i before < and && are evaluated at all?
On the other hand,
int index = 4;
a[index] = index = index-2;
changes a[4], not a[2], so [] is evaluated before the operands of the right-hand =.
I can answer this stuff from a compiler (abstract syntax tree) perspective, but not from a language rules perspective.