相关疑难解决方法(0)

C++中编译器和评估的参数顺序

好吧,我知道标准规定C++实现可以选择评估函数的哪个顺序参数,但是在实际影响程序的情况下是否有任何实现"利用"它的实现?

经典示例:

int i = 0;
foo(i++, i++);
Run Code Online (Sandbox Code Playgroud)

注意:我不是在找人告诉我评估的顺序不能依赖,我很清楚这一点.我只对任何编译器是否真的按照从左到右的顺序进行评估感兴趣,因为我的猜测是,如果他们做了很多写得不好的代码就会破坏(这是正确的,但他们仍然可能会抱怨).

c++ operator-precedence

59
推荐指数
4
解决办法
2万
查看次数

Function interleaving in pre C++17

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)

c++ language-lawyer c++11 c++14 c++17

3
推荐指数
1
解决办法
187
查看次数

标签 统计

c++ ×2

c++11 ×1

c++14 ×1

c++17 ×1

language-lawyer ×1

operator-precedence ×1