好吧,我知道标准规定C++实现可以选择评估函数的哪个顺序参数,但是在实际影响程序的情况下是否有任何实现"利用"它的实现?
经典示例:
int i = 0;
foo(i++, i++);
Run Code Online (Sandbox Code Playgroud)
注意:我不是在找人告诉我评估的顺序不能依赖,我很清楚这一点.我只对任何编译器是否真的按照从左到右的顺序进行评估感兴趣,因为我的猜测是,如果他们做了很多写得不好的代码就会破坏(这是正确的,但他们仍然可能会抱怨).
Look at this simple function call:
f(a(), b());
Run Code Online (Sandbox Code Playgroud)
According to the standard, call order of a() and b() is unspecified. C++17 has the additional rule which doesn't allow a() and b() to be interleaved. Before C++17, there was no such rule, as far as I know.
Now, look at this simple code:
int v = 0;
int fn() {
int t = v+1;
v = t;
return 0;
}
void foo(int, int) { }
int main() {
foo(fn(), fn());
} …Run Code Online (Sandbox Code Playgroud)