简体   繁体   中英

Does int a=1, b=a++; invoke undefined behavior?

Does 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; an initializer is specified to give the "initial value" of the object. Per 6.7.8 Initialization, paragraph 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. 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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