简体   繁体   中英

Order of evaluation of expressions in a function call

Given a function call func(E1, E2, E3) where E1 etc are arbitrary expressions, is it true that each expression is indeterminately sequenced with respect to each other expression, or are all the expressions unsequenced (ie the evaluations can overlap)?

I've looked at the cppreference page on this and it, in rule 15, uses the sentence

In a function call, value computations and side effects of the initialization of every parameter are indeterminately sequenced with respect to value computations and side effects of any other parameter.

which I don't think is quite the same as what I'm asking as the initialisation of the parameter is just the last step in evaluation of the parameter's expression.

But rule 21 which is talking about something else seems to imply that each sub-expression in a function call is indeterminately sequenced

Every expression in a comma-separated list of expressions in a parenthesized initializer is evaluated as if for a function call (indeterminately-sequenced)

So I'm a bit confused and any guidance is appreciated.

C++17 states in

8.2.2 Function call [expr.call]

4... The initialization and destruction of each parameter occurs within the context of the calling function.


5... Note: All side effects of argument evaluations are sequenced before the function is entered


5... The initialization of a parameter, including every associated value computation and side effect, is indeterminately sequenced with respect to that of any other parameter.

I hope this (my bolding) is clear enough.

(ref: n4659, final C++17 draft )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM