c/language/eval order

Order of evaluation of the operands of any C operator, including the order of evaluation of function arguments in a function-call expression, and the order of evaluation of the subexpressions within any expression is unspecified (except where noted below). The compiler will evaluate them in any order, and may choose another order when the same expression is evaluated again.

There is no concept of left-to-right or right-to-left evaluation in C, which is not to be confused with left-to-right and right-to-left associativity of operators: the expression is parsed as  due to left-to-right associativity of operator+, but the function call to  may be evaluated first, last, or between  or  at run time.

Evaluations
There are two kinds of evaluations performed by the compiler for each expression or subexpression (both of which are optional):
 * value computation: calculation of the value that is returned by the expression. This may involve determination of the identity of the object or reading the value previously assigned to an object (rvalue evaluation)
 * side effect: access (read or write) to an object designated by a lvalue, modification (writing) to an object, modifying a file, modifying the floating-point environment (if supported), or calling a function that does any of those operations.

If no side effects are produced by an expression and the compiler can determine that the value is not used, the expression.

Ordering
"sequenced-before" is an asymmetric, transitive, pair-wise relationship between evaluations within the same thread (it may extend across threads if atomic types and memory barriers are involved).


 * If a sequence point is present between the subexpressions E1 and E2, then both value computation and side effects of E1 are sequenced-before every value computation and side effect of E2

Rules
@1@ There is a sequence point after the evaluation of all function arguments and of the function designator, and before the actual function call. @2@ There is a sequence point after evaluation of the first (left) operand and before evaluation of the second (right) operand of the following binary operators: (logical AND),  (logical OR), and  (comma). @3@ There is a sequence point after evaluation of the first (left) operand and before evaluation of the second or third operand (whichever is evaluated) of the conditional operator @4@ There is a sequence point after the evaluation of a full expression (an expression that is not a subexpression: typically something that ends with a semicolon or a of ///) and before the next full expression.

Undefined behavior
@1@ If a side effect on a scalar object is unsequenced relative to another side effect on the same scalar object, the.

@2@ If a side effect on a scalar object is unsequenced relative to a value computation using the value of the same scalar object, the behavior is undefined.

@3@ The above rules apply as long as at least one allowable ordering of subexpressions permits such an unsequenced side-effect.