i = ++i + i;

In C99  --- 6.5 Expressions

Between the previous and next sequence point an object shall have its stored value
modified at most once by the evaluation of an expression. Furthermore, the prior value
shall be read only to determine the value to be stored

2. Between the previous and next sequence point an object shall have its stored valuemodified at most once by the evaluation of an expression. Furthermore, the prior value shall be read only to determine the value to be stored.

3. The grouping of operators and operands is indicated by the syntax. Except as specified later (for the function-call (), &&, ||, ?:, and comma operators), the order of evaluation of subexpressions and the order in which side effects take place are both unspecified

 

In C++ ISO/IEC 14882:2003 --- 5 Expressions

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.53) Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored.The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined.

 

So undefined:

i = v[i++];

i = ++i + 1;

while allowing

i = i + 1;

a[i] = i;

 

原文链接: https://www.cnblogs.com/aoaoblogs/archive/2010/05/31/1748103.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    i = ++i + i;

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/11342

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月7日 上午1:09
下一篇 2023年2月7日 上午1:10

相关推荐