C 中的初始化列表和序列点
C 标准规定,在完整的末尾有一个序列点 然而,这
initializer:
assignment-expression
{ initializer-list }
{ initializer-list , }
initializer-list:
initializer
initializer-list , initializer
意味着这
int a[2] = { i = 1 , ++i };
应该没问题。有人可以解释一下为什么会出现这种情况吗?
The C Standard states that there is a sequence point at the end of a full
expression in an initializer and that
initializer:
assignment-expression
{ initializer-list }
{ initializer-list , }
initializer-list:
initializer
initializer-list , initializer
That would mean, however, that this
int a[2] = { i = 1 , ++i };
ought to be fine. Could someone please explain why, or why not, this is the case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道你在哪里看到的。我看到 https://port70.net/~nsz/c/ c11/n1570.html#6.7.9p23:
它“很好”,因为行为被定义为未指定行为。您不知道
i = 1
或++i
中的哪一个将首先执行或最后执行,其中一个会执行。I do not know where you see that. I see https://port70.net/~nsz/c/c11/n1570.html#6.7.9p23 :
It is "fine", as in the behavior is defined to be unspecified behavior. You do not know, which one of
i = 1
or++i
will execute first or last, one of them will.