简体   繁体   English

c ++优先顺序..该表达式如何求值?

[英]c++ order of preference.. how is this expression evaluated?

I am trying to understand code of some library of one simulation tool that i use.. It has the following line: 我试图了解我使用的一种仿真工具的某些库的代码。它具有以下行:

propData->fadingStretchingFactor =
        (double)(propProfile0->samplingRate) *
        propProfile->dopplerFrequency /
        propProfile0->baseDopplerFrequency /
        (double)SECOND;

Now how do u figure out the order of operations if there are two consecutive division operators as in this example 现在,如本例中所示,如果有两个连续的除法运算符,如何计算运算顺序

Division is left associative. 除法是左联想。 a / b / c is equivalent to (a / b) / c . a / b / c等效于(a / b) / c

Note that C (and C++) do not guarantee any ordering between the evaluations of the terms a , b , and c . 请注意,C(和C ++)不保证对abc的求值之间的任何排序。 For example, foo() / bar() could call foo() before bar() or foo() after bar() . 例如, foo() / bar()可以调用foo()之前bar()foo()bar()

The grouping of operations of equal precedence is determined by operator associativity . 优先级相同的操作分组由操作员关联性确定。

In C++, division is left-associative , which means that the leftmost operation is grouped first, ie: 在C ++中,除法为left-associative ,这意味着最左边的操作首先分组,即:

a / b / c

is the same as: 是相同的:

(a / b) / c

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM