任何好的理由赋值运算符是不是一个顺序点? [英] Any good reason why assignment operator isn't a sequence point?

查看:102
本文介绍了任何好的理由赋值运算符是不是一个顺序点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么好的理由运算符= 不是一个顺序点?无论是在C和C ++。

Is there any good reason for operator = not being a sequence point? Both in C and C++.

我有麻烦思考一个反例。

I have trouble thinking about an counter-example.

推荐答案

通过要求:

在一般情况下,事情需要一个理由为序列点。他们不需要理由的不可以是一个顺序点;这是默认的。

In general, things need a reason to be a sequence point. They don't need a reason not to be a sequence point; that's the default.

例如,&放大器;&安培; 必须是因为短路行为序列点:如果左边是假的,右手边< STRONG>不得进行评估。 (这不只是关于优化;右手边可能有副作用,和/或取决于左侧是真实,如 PTR和放大器;&安培; ptr-&GT;数据)。因此左手侧必须首先计算,右手边前,为了查看是否右侧应在所有评估

For example, && must be a sequence point because of short-circuiting behaviour: if the left-hand side is false, the right-hand side must not be evaluated. (This is not just about optimization; the right-hand side could have side effects, and/or depend on the left-hand side being true, as in ptr && ptr->data.) Therefore the left-hand side must be evaluated first, before the right-hand side, in order to see if the right-hand side should be evaluated at all.

这个理由不存在了 = 因为,虽然有评价​​为双方做(尽管有什么可以在两侧出现不同程度的限制:在左侧必须是一个左值 - 的 L不能代表左,顺便说一句,它的全称是位置,如在内存中的位置 - 我们不能分配到临时或文字),它无关紧要哪一方先计算 - 只要双方都实际转让前评估

This reason does not exist for = because, although there is "evaluation" to do for both sides (although there are different restrictions on what can appear on both sides: the left-hand side must be an lvalue - the l doesn't stand for "left", btw; it stands for "location", as in location in memory - we can't assign to a temporary or a literal), it doesn't matter which side is evaluated first - as long as both sides are evaluated before the actual assignment.

这篇关于任何好的理由赋值运算符是不是一个顺序点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆