Unspecified evaluation order for function arguments in C
24.5K reputation · 20 Sept 2021, 05:58 UTC
C leaves the order in which function arguments and operands of most operators are evaluated unspecified, and it leaves sequencing of side effects to sequence points. This documented unspecified behavior means the same source can be legal yet produce different observable results across implementations and optimization levels.
The goal is to characterize the portability boundary for code that must remain consistent across compilers and targets. The constraint is the standard's intentional lack of ordering guarantees, which creates an unresolved decision for developers about whether to rely on observed behavior or rewrite to avoid dependence.
Does the C standard provide any sequencing guarantees for argument evaluation beyond sequence points? Which expressions are guaranteed to have a defined evaluation order in current standards? When does reliance on a particular order become non-portable across conforming implementations?