I have just joined and this is my first post.
I have never been able to resolve the issue of order of evaluation in
C/C++ and the related issue of precedence of operators, use of
parentheses.
>From the reference manual I have :-1) "The order of evaluation of subexpressions is determined by the
precedence and grouping of operators."
2) order of evaluation of operands of operators undefined except where
noted.
I was just told at another forum that
v = u - ((u & -(u = 1)) << 1);
has undefined behavior and the reason given was
the order of evaluation of operands u, -(u = 1) of & is undefined.
That unary - has the highest precedence or the use of parentheses in -
(u = 1) is of no consequence.
Also all over the internet, the impression I get about
x = a * b + c;
is that the order of evaluation is a * b, ? + c, x = ?
But the order(undefined) of evaluation may be (c) , a * b,
x = ? + ?
The same person seem to say unequivocally (?) that precedence
of operators has nothing to do with order of evaluation, but only
about binding operands to operators.
So I have the following questions :-
1) v = u - ((u & -(u = 1)) << 1); Is this undefined and why?
2) Does precedence of operators determine order of evaluation ? If
Yes, then in what situations.
3) If answer to 2) is No, then how is C affected if precedence of
operators is redefined in sort of this manner :-
"precedence of operators determines the grouping of operands with
operators" - without any reference to order of evaluation.
Best Regards,
Rasjid