简体   繁体   English

递增运算符和“未定义的行为”

[英]Increment operators and “undefined behaviour”

As mentioned in the comp.lang.c FAQ , the C standard states: comp.lang.c FAQ中所述,C标准规定:

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 accessed only to determine the value to be stored. 此外,只能访问先前值以确定要存储的值。

But, this (now deleted) article says that a = ++b + ++c; 但是,这篇(现已删除的)文章a = ++b + ++c; is undefined. 未定义。 Could someone please explain why this is undefined behaviour? 有人可以解释为什么这是未定义的行为?

Provided the objects involved ( a , b and c ) in the expression a = ++b + ++c; 假设涉及的对象( abc )在表达式a = ++b + ++c; are distinct, that expression is well-defined. 是不同的,表达是明确的。

Perhaps, the author meant to use the same variable twice such as a = ++b + ++b; 也许,作者意味着两次使用相同的变量,例如a = ++b + ++b; . I can only speculate. 我只能推测。 But there's no undefinedness in the given expression. 但是在给定的表达式中没有任何不确定性。

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

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