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

标签 c language-lawyer operator-precedence sequence-points c17

在今天偶然发现“ 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/

相关文章:

java - Java和Javascript计算结果的差异

c - c 中的运算符和优先级

c++ - ffmpeg c/c++ 获取帧数或时间戳和 fps

c++ - 什么场景会**有用?

c++ - &= 必须始终被解释为运算符吗?

c++ - std::optional 值的地址是否稳定?

谁能帮我解释一下这段代码吗?

Python:具有两个变量的 C for 循环

c++ - std::unordered_set::equal_range 迭代器问题

c# - 方法的优先顺序?