[英]Initializer lists in C and sequence points
The C Standard states that there is a sequence point at the end of a full expression in an initializer and that C 标准声明在初始化器中完整表达式的末尾有一个序列点,并且
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?有人可以解释为什么会这样吗?
I do not know where you see that.我不知道你在哪里看到的。 I see https://port70.net/~nsz/c/c11/n1570.html#6.7.9p23 :我看到https://port70.net/~nsz/c/c11/n1570.html#6.7.9p23 :
The evaluations of the initialization list expressions are indeterminately sequenced with respect to one another and thus the order in which any side effects occur is unspecified.初始化列表表达式的求值相对于彼此的顺序是不确定的,因此任何副作用发生的顺序是未指定的。
ought to be fine.应该没问题Could someone please explain why有人可以解释为什么
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.您不知道, i = 1
或++i
中的哪一个将首先执行或最后执行,其中一个将执行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.