c - 为什么 C99 中的这个语句在 C11 中发生了变化?

标签 c object language-lawyer c99 c11

C99标准:

Between the previous and next sequence point an object shall have its stored value modified at most once by the evaluation of an expression



C11标准:

If a side effect on a scalar object is unsequenced relative to another side effect on the same scalar object, the behavior is undefined.



C99 标准的这个定义也是不完整的,因此它在 C11 中更新,因为它只包含术语 object而不是 scalar object ?

最佳答案

这是因为 C11 试图涵盖多线程/并行执行。 “抽象机器”中程序执行的基本规则在C99和C11之间添加了这段繁琐的文字(C11 5.1.2.3/3):

Sequenced before is an asymmetric, transitive, pair-wise relation between evaluations executed by a single thread, which induces a partial order among those evaluations. Given any two evaluations A and B, if A is sequenced before B, then the execution of A shall precede the execution of B. (Conversely, if A is sequenced before B, then B is sequenced after A.) If A is not sequenced before or after B, then A and B are unsequenced. Evaluations A and B are indeterminately sequenced when A is sequenced either before or after B, but it is unspecified which.13) The presence of a sequence point between the evaluation of expressions A and B implies that every value computation and side effect associated with A is sequenced before every value computation and side effect associated with B. (A summary of the sequence points is given in annex C.)



因此,您引用的部分 (C99 6.5/2) 进行了相应的更改,以适应抽象机中程序执行的定义,据说现在也涵盖了并行执行。不幸的是 - 由于 C99 文本更具可读性。从技术上讲,如果不考虑并行执行,则根本没有任何变化。 C99 中关于序列点的规则仍然适用,只是措辞不同。此更改还意味着将 C11 与具有类似规则的 C++11 同步。

关于c - 为什么 C99 中的这个语句在 C11 中发生了变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61653812/

相关文章:

c++ - 是否允许实现将公共(public)成员添加到标准类型?

c++ - 为什么禁止在后续的私有(private)派生类中简单提及基指针/引用?

C - 我认为我做错了 realloc

java - 如何在 Java 中将 Object 转换为 NameValuePair ArrayList?

调用非静态方法的Java静态引用变量

javascript - 为对象提供添加对象的方法

c++ - 为什么 C++ 函数参数包必须是占位符或包扩展?

c - 为什么我的链表内容在退出函数后就消失了?

c - 如何在库加载时将参数传递给构造函数?

c - C 语言的多客户端服务器实现