[英]Does int a=1, b=a++; invoke undefined behavior?
Does int a=1, b=a++;
int a=1, b=a++;
invoke undefined behavior? 调用未定义的行为? There is no sequence point intervening between the initialization of
a
and its access and modification in the initializer for b
, but as far as I can tell, initialization is not "modification" of the object; 还有就是初始化介于其间没有顺序点
a
和在初始化的访问和修改b
,但据我所知,初始化是不是对象的“修改”; an initializer is specified to give the "initial value" of the object. 指定初始值设定项以提供对象的“初始值”。 Per 6.7.8 Initialization, paragraph 8:
根据6.7.8初始化,第8段:
An initializer specifies the initial value stored in an object.
初始值设定项指定存储在对象中的初始值。
and it seems reasonable to take "initial" as being sequenced before any access to the object. 在对对象进行任何访问之前,将“initial”作为顺序进行似乎是合理的。 Has this issue been considered before, and is there an accepted interpretation?
此问题是否已经考虑过,是否有可接受的解释?
It doesn't invoke undefined behaviour. 它不会调用未定义的行为。 In 6.7.6 (3), it is stated
在6.7.6(3)中,陈述
A full declarator is a declarator that is not part of another declarator.
完整声明者是不属于另一个声明者的声明者。 The end of a full declarator is a sequence point.
完整声明符的结尾是一个序列点。
that the end of a full declarator is a sequence point. 完整声明符的结尾是一个序列点。
int a = 1, b = a++;
// ^ end of full declarator
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.