操作数的计算顺序 [英] order of evaluation of operands

查看:170
本文介绍了操作数的计算顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在除权pression A + B A 保证被评估之前 b ,或者是评估未指定的顺序?我认为是后者,但我很难找到标准的一个明确的答案。

由于我不知道C是否处理从C ++这种不同的,如果为了评价规则进行了简化在C ++ 11,我会标记了一个问题,所有三个。


解决方案

在C ++中,对于用户自定义类型 A + B 是一个函数调用,标准说


  

    

§5.2.2.8 - [...]函数参数的评估顺序为未指定。 [...]


  

有关运营商正常的标准说:


  

    

第5.4节 - 除非另有说明,个体经营者和个人前pressions的SUBEX pressions,并在其中的副作用发生的顺序,操作数的计算顺序为未指定。 [...]


  

这些都没有改变对C ++ 11。然而,在第二个的措词变化的说,顺序是 unsequenced 的,而不是未指定的,但是它在本质上是一样的。

我没有C标准的副本,但我想,这是同有作为。

In the expression a + b, is a guaranteed to be evaluated before b, or is the order of evaluation unspecified? I think it is the latter, but I struggle to find a definite answer in the standard.

Since I don't know whether C handles this different from C++, or if evaluation order rules were simplified in C++11, I'm gonna tag the question as all three.

解决方案

In C++, for user-defined types a + b is a function call, and the standard says:

§5.2.2.8 - [...] The order of evaluation of function arguments is unspecified. [...]

For normal operators, the standard says:

§5.4 - Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. [...]

These haven't been changed for C++11. However, the wording changes in the second one to say that the order is "unsequenced" rather than unspecified, but it is essentially the same.

I don't have a copy of the C standard, but I imagine that it is the same there as well.

这篇关于操作数的计算顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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