是否有关于“i=i--”行为的具体文档?在海湾合作委员会?

发布于 2024-09-15 23:15:18 字数 411 浏览 1 评论 0原文

再次,我们最喜欢的“i=i--”之类的问题。在 C99 中我们有:

6.5 表达式 #2:上一个序列点和下一个序列点之间 对象应有其存储值 最多修改一次

70) 本段呈现 !!不明确的!!语句表达式 比如

i = ++i + 1;

但是对于未定义的行为,可能存在从随机输出到“以记录方式执行程序”的变体(c99 3.4.3)

因此,问题是:

gcc 是否记录了 i=i++ 的行为, i=i--等等语句?

实际代码是

int main(){int i=2;i=i--;return i;}

Once again, our best loved "i=i--" -like issues. In C99 we have:

6.5 Expressions #2: Between the previous and next sequence point an
object shall have its stored value
modified at most once

70) This paragraph renders
!!undefined!! statement expressions
such as

i = ++i + 1;

But for undefinded behavior there can be variants from random output to "program execution in a documented manner" (c99 3.4.3)

So, the question:

Does gcc document the behavior for i=i++, i=i--, and so on statements?

Actual code is

int main(){int i=2;i=i--;return i;}

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

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

发布评论

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

评论(4

很糊涂小朋友 2024-09-22 23:15:19

你到底为什么要这么做?严重地。我很好奇。

why on earth would you want to do that? Seriously. I'm curious.

爱已欠费 2024-09-22 23:15:18

GCC 没有记录此行为。 警告选项页面提到了 -Wsequence 中的序列点问题-point,但没有暗示明确定义的违规语义。

GCC 确实有一个很好的 C 列表实现定义的行为,但我在这里也找不到任何对此问题的参考。

GCC does not document this behaviour. The Warning Options page mentions sequence points issues in -Wsequence-point, but does not hint at well-defined sematics for violations.

GCC does have a nice list of C Implementation Defined Behaviour, but I could not find any reference to this issue here either.

牵你手 2024-09-22 23:15:18

由后端实现来决定它的作用。您可以使用 -S 并检查生成的代码以确定事件的确切顺序。

It's left to the back-end implementation to decide what it does. You can use -S and inspect the generated code to determine the exact sequence of events.

是你 2024-09-22 23:15:18

它没有记录,但即使有,我也不想读它。当遇到未定义的行为时,您永远不应该依赖特定实现的功能。

It is not documented but even it it was, I wouldn't want to read it. You should never rely on what a particular implementation does when running into undefined behavior.

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