Are there any situations where code would have a sequence point in c++11 but not c++03?

萝らか妹 提交于 2019-12-04 18:54:18

问题


Now that the new c++11 standard has made changes in how sequence points are described I'm trying to find out exactly what has been changed between c++03 and c++11.

In particular, are there any situations where code that looks the same would have a sequence point in c++11 but not c++03?


回答1:


There are no sequence points in C++11, rather there are sequenced before and sequenced after relations.

Here are some trivial examples wherein behavior differ between C++03 and C++11

int x = 10;
++++x; // well defined in C++11

int x = 10;
x = ++x +1; //well defined in C++11

Why? Have a look at this answer and related threads.




回答2:


I think the best known example is the pre-increment operator.

int i = 0;
++ ++ ++ i;

In C++03, this would be UB, and in C++11, each assignment is ordered before the next evaluation.

Searching the Standard for differences is tough because they got rid of the "sequence point" terminology in favor of "ordered before" and the like, and rewrote much of the rules from scratch.



来源:https://stackoverflow.com/questions/9293595/are-there-any-situations-where-code-would-have-a-sequence-point-in-c11-but-not

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!