Does this code from “The C++ Programming Language” 4th edition section 36.3.6 have well-defined behavior?

The code exhibits unspecified behavior due to unspecified order of evaluation of sub-expressions although it does not invoke undefined behavior since all side effects are done within functions which introduces a sequencing relationship between the side effects in this case. This example is mentioned in the proposal N4228: Refining Expression Evaluation Order for Idiomatic C++ … Read more

Operator precedence with JavaScript’s ternary operator

Use: h.className = h.className + (h.className ? ‘ error’ : ‘error’) You want the operator to work for h.className. Better be specific about it. Of course, no harm should come from h.className += ‘ error’, but that’s another matter. Also, note that + has precedence over the ternary operator: JavaScript Operator Precedence

Ternary conditional and assignment operator precedence

The operator precedence in the C/C++ language in not defined by a table or numbers, but by a grammar. Here is the grammar for conditional operator from C++0x draft chapter 5.16 Conditional operator [expr.cond]: conditional-expression: logical-or-expression logical-or-expression ? expression : assignment-expression The precedence table like this one is therefore correct when you use assignment on … Read more

Is Python’s order of evaluation of function arguments and operands deterministic (+ where is it documented)?

Yes, left to right evaluation order is guaranteed, with the exception of assignments. That’s documented here (py2, py3): Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. In the following lines, expressions will be evaluated in the arithmetic order of their suffixes: … Read more

Why does the expression a = a + b – ( b = a ) give a sequence point warning in c++?

There is a difference between an expression being evaluated and completing its side effects. The b = a assignment expression will be evaluated ahead of subtraction due to higher precedence of the parentheses. It will provide the value of a as the result of the evaluation. The writing of that value into b, however, may … Read more