Quote:
Originally Posted by j.p.s
C compilers, by default, feel free to ignore arithmetic operator precedence, even when parentheses are used to (attempt to) force operation order.
|
Quote:
Originally Posted by jbjb
No non-broken C compiler should ignore operator precedence. It just might not mean what you think it does - e.g. it doesn't control the order of evaluation of operands, only the order of execution of the operators (and even then compilers are allowed to reorder expressions so long as it doesn't alter the observable behaviour of the program). K&R C gave a bit more latitude around reordering expressions that were mathematically associative or commutative, but not necessarily computationally so, but ANSI/ISO C tightened that up.
Obviously, if your program has undefined behaviour, then the compiler can do whatever it wants, but the problem there is with the undefined behaviour, not the reordering!
|
Sorry, I miswrote what I was trying to express. I wasn't thinking about precedence at all, but indeed order of evaluation.
Reordering can be mathematically equivalent but still give significantly different computed results, especially if large and small quantities are present in the same expression.
I think that parentheses should be sacred unless an optimization flag to the contrary is explicitly set.