int a()
{
return 1;
}
int b()
{
return 2;
}
int c()
{
return 3;
}
int g(int, int)
{
return 0;
}
void f(int, int)
{}
int main()
{
f(g(a(), b()),
c());
}
I know the evaluation order of function arguments is unspecified as per the C++ standard.
In other words, the actual evaluation order may be:
a(), b(), c()
c(), a(), b()
b(), a(), c()
c(), b(), a()
I just wonder:
Does the C++ stardard guarantee c()
will never be called between a()
and b()
?
I guess it is guaranteed since C++17. N4659 (March 2017 post-Kona working draft/C++17 DIS) [intro.execution]/18, reads:
For each function invocation
F
, for every evaluationA
that occurs withinF
and every evaluationB
that does not occur withinF
but is evaluated on the same thread and as part of the same signal handler (if any), eitherA
is sequenced beforeB
orB
is sequenced beforeA
. In other words, function executions do not interleave with each other.
Before C++17 we had no such guarantees.