c++ - C++11赋值运算符副作用的求值顺序

标签 c++ c++11

如果有人能澄清 C++11 中赋值语句的副作用顺序,我将不胜感激。例如,指出处理它的相关标准文本。

evaluation order上的页面在 cppprefence.com 上声明了以下有关分配的内容:

8) The side effect (modification of the left argument) of the built-in assignment operator and of all built-in compound assignment operators is sequenced after the value computation (but not the side effects) of both left and right arguments, and is sequenced before the value computation of the assignment expression (that is, before returning the reference to the modified object)

“(但不是副作用)”是什么意思?副作用是未排序不确定排序还是修改后排序左边的参数(或者甚至可能引用返回之后排序?

例如,后增量操作何时发生在: while (*tgt++= *src++);

evaluation order看来很清楚首先进行值计算,因此首先计算*tgt*src。但是否知​​道增量后副作用何时发生?

编辑#1:

Undefined behavior and sequence points尽我最大的理解不回答我的问题。事实上,这是我掉入“兔子洞”的开始,最终将我带到了 cppreference.com。我特别想知道的是 C++11 中赋值运算符副作用的排序定义。 Undefined behavior and sequence points 中回答的问题是排序未定义未指定行为实现特定行为概念之间的关系。顺便说一句,它回答得很好。

编辑 #1 结束

最好的问候

最佳答案

What is meant by "(but not the side effects)?

这句话强调了一个事实,即该句子没有对副作用的顺序做出任何声明。

Are the side effects unsequenced, inderminately sequenced or sequenced after the modification of the left argument (or perhaps even sequenced after the returning of the reference?

这是在讨论每个特定副作用的段落中确定的。例如,后缀递增运算符的副作用在其值计算之后进行排序,并且声明不确定顺序的函数调用不能干预。我找不到关于此运算符排序的其他声明。如果确实没有,则必须得出结论,它是未排序的 w.r.t.作业。

关于c++ - C++11赋值运算符副作用的求值顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53517119/

相关文章:

c++ - 选择 3D 游戏引擎

android - 错误 : '__NDK_FPABI__' does not name a type. 版本 2

c++ - 全局新运算符重载

haskell - C++11 相当于 Haskell 的 "inits"

c++ - CRTP与完美转发

c++ - 寻求有关消耗多个值的 C++11 printf 格式参数的解释

c++ - 线程连接问题

c++ - 如何在类外声明特化模板方法?

c++ - std::shared_ptr 什么时候释放它的对象?

c++ - 从 SQL Server 在 C++ native 客户端中返回 NULL 数据类型