If we have three functions (foo, bar, and baz) that are composed like so...
foo(bar(), baz())
Is there any guarantee by the C++ standard th
From [5.2.2] Function call,
The order of evaluation of arguments is unspecified. All side effects of argument expression evaluations take effect before the function is entered.
Therefore, there is no guarantee that bar()
will run before baz()
, only that bar()
and baz()
will be called before foo
.
Also note from [5] Expressions that:
except where noted [e.g. special rules for
&&
and||
], the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified.
so even if you were asking whether bar()
will run before baz()
in foo(bar() + baz())
, the order is still unspecified.