Say, in the following test expression:
int ggg9 = fggg2() + (fggg3() && fggg4() < fggg5() * fggg6());
// 4 11 6 3
if we follow the operator precedence (shown in the line with comments below the expression) I would assume that the expression in parens will be evaluated first and then the result will be added to fggg2()
.
Thus I'd assume that it will be resolved in this order:
int r1 = fggg5() * fggg6(); //Precedence 3 (inside parens)
int r2 = fggg4() < r1; //Precedence 6 (inside parens)
int r3 = fggg3() && r2; //Precedence 11 (inside parens)
int ggg9 = fggg2() + r3; //Outside of parens, so it's last
But x86-64 gcc 8.2
resolves it as such:
(I'll convert it back to C++)
int i0;
int r2 = fggg2();
int r3 = fggg3();
if(!r3) goto L13;
int r4 = fggg4();
int r5 = fggg5();
int r6 = fggg6();
int i1 = r5 * r6;
if(r4 >= i1) goto L13
i0 = 1;
goto L14
L13:
i0 = 0;
L14:
int ggg9 = i0 + r2;
So why is the &&
operator seems to be evaluated before *
and then <
when their precedence is 11, 3, 6, respectively?
Lastly, how come it doesn't seem to care about parens by evaluating fggg2()
first? VS2017 seems to be evaluating it last.
From what I see, the gcc
compiler simply evaluated all those functions from left-to-right without any regard to precedence.