gpt4 book ai didi

c - i=i++ 会在 C17 中重新定义吗?

转载 作者:太空狗 更新时间:2023-10-29 16:44:44 26 4
gpt4 key购买 nike

在今天偶然发现“ Why are these constructs using pre and post-increment undefined behavior? ”这个问题后,我决定获取我能找到的下一个 C 标准的最新草案并阅读更多相关信息。
在我发现 C17 草案中的以下段落后不久:

An expression is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof. The value computations of the operands of an operator are sequenced before the value computation of the result of the operator
Source: ISO/IEC 9899:2017, Section 6.5 §1 "Expressions" (link broken use web.archive.org)

现在我有点迷茫了。这是否意味着 i = i++ 是已定义的行为?这次我看了另一个草稿,C99:

An expression is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof.
Source: ISO/IEC 9899:1999, Section 6.5 §1 "Expressions"

它漏掉了那句话!

问题

  1. 我是不是误会了什么?
  2. 答案是否过时?
  3. 我看错草稿了吗?

注意:this question是相关的,但它是关于 C++ 的。

最佳答案

您突出显示的段落仅说明表达式 i++i 在完整表达式 i = i++ 的求值之前求值。它仍然是未定义的行为,因为 i 在没有序列点的表达式中被修改了不止一次。

那段话首次出现在 C11 , 因此与 C17 版本相比没有变化。

关于c - i=i++ 会在 C17 中重新定义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53468432/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com