是否存在代码在 c++11 中具有序列点但在 c++03 中没有的情况?

发布于 2025-01-05 08:14:15 字数 126 浏览 1 评论 0原文

现在新的 c++11 标准已经对序列点的描述方式进行了更改,我正在尝试找出 c++03 和 c++11 之间到底发生了什么变化。

特别是,是否存在看起来相同的代码在 c++11 中具有序列点但在 c++03 中没有的情况?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我还不会笑 2025-01-12 08:14:15

C++11 中没有顺序点,而是存在顺序前和顺序后的关系。

以下是一些简单的示例,其中 C++03 和 C++11 之间的行为有所不同,

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

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

为什么?查看答案和相关线程。

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.

自控 2025-01-12 08:14:15

我认为最著名的例子是预增量运算符。

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

在 C++03 中,这将是 UB,而在 C++11 中,每个赋值都在下一次求值之前排序。

在标准中寻找差异是很困难的,因为他们摆脱了“序列点”术语,转而使用“顺序点”等类似术语,并从头开始重写了许多规则。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文