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

自古美人都是妖i 提交于 2019-12-03 11:16:52

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/16219082/does-int-a-1-b-a-invoke-undefined-behavior

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!