Next: , Up: Expression Evaluation   [Index]


3.15.1 Evaluation Order

Expressions are evaluated left to right and always in order. There are thus differences from C expression evaluation order.

Binary operators evaluate left to right, though some associate right to left (like the C assignment operators).

Differences from C expression evaluation are due to always in order rule. Thus a subexpression occuring before a second subexpression is always evaluated before the same second subexpression. Function arguments are not evaluated before the expression.

(x = 0) + cos(x)’ expression evaluates to 1, no matter the value of assumed numeric variable ‘x’ before expression evaluation and assuming a cosine function called ‘cos’. A C compiler (like the one I am using now) still evaluates the expression to 1, yet it claims that ‘operation on `x' may be undefined’.

Assuming a ‘real modf(real, real &)’ function with C modf semantics and two real variables, ‘e’ and ‘f’, valued 2.5 and 4, respectively, the expression ‘f + 0 * modf(e, f)’ evaluates to 4 (‘f’ will be set to 2). The C expression f + 0 * modf(e, &f), where both e and f are doubles, evaluates to 2 (and sets f to 2) (at least the compiler I am using does so).