标签:c operator-precedence parameters
在该标准的早期版本(C 03)中,未指定对函数调用的参数评估顺序.
在标准的后续版本(C 11或C 14)中是否对此进行了更改?
即我们是否可以依赖特定的顺序(从左到右).
解决方法:
不,这没有改变,但是最近有一个更改提议:N4228: Refining Expression Evaluation Order for
Idiomatic C++,这是Pre-Urbana mailing that came out this October的一部分引言说(强调我的前进):
Expression evaluation order is a recurring discussion topic in the
C++ community. In a nutshell, given an expression such as f(a, b, c),
the order in which the sub-expressions f , a , b , c are evaluated
is left unspecified by the standard. If any two of these
sub-expressions happen to modify the same object without intervening
sequence points, the behavior of the program is undefined. For
instance, the expression f(i++, i) where i is an integer variable
leads to undefined behavior
它建议:
We propose to revise C++ evaluation rules to support decades-old
idiomatic constructs and programming practices. A simple solution
would be to require that every expression has a well-defined
evaluation order. That suggestion has traditionally met resistance for
various reasons. Rather, this proposes suggests a more targeted fix
- Postfix expressions are evaluated from left to right. This includes
functions calls and member section expressions.- Assignment expressions are evaluated from right to left. This includes compound assignments.
- Operands to shift operators are evaluated from left to right
更新
Herb Sutter最近put out a poll on order of evaluation希望从社区中获得一些对我们期望从以下代码中获得什么结果的反馈:
std::vector<int> v = { 0, 0 };
int i = 0;
v[i++] = i++;
std::cout << v[0] << v[1] << endl;
这似乎表明委员会正在认真考虑评估顺序的问题,但是正如我们从讨论中看到的那样,这是有争议的.
标签:c,operator-precedence,parameters 来源: https://codeday.me/bug/20191009/1880732.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。