Consider printf("%g and %g\n", f(a), f(b));. C does not specify whether f(a) or f(b) is evaluated first. If either call has side effects, the result can depend on compiler choices, options, or surrounding code. section 4.5
printf("%g and %g\n", f(a), f(b));
!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":6}]]"}
!@%STYLE%@!
Use the call expression to inspect the two argument expressions whose relative evaluation order is unspecified. section 4.5
TAKEAWAY: distinguish the operators that impose order from those that do not.
- &&, ||, ?:, and the comma operator evaluate their first operand first. section 4.5
- The comma operator evaluates operands left to right and produces the right operand's value; do not confuse it with commas separating function arguments or initializations. section 4.5
- Most operators and function calls do not sequence their operands or argument expressions. section 4.6
- Avoid side effects in functions called inside expressions, and do not use the comma operator in clean code. section 4.5
