C说:
(C11, 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.”
并在C99
(C99, 6.7.8p23) “The order in which any side effects occur among the initialization list expressions is unspecified.”
这就是说声明
bool condition[10] = {true,condition[5]=true};
可以有同样的行为:
bool condition[10] = {true, 1};
或作为
bool condition[10] = {true, 1, [5] = true};
condition [5] = true评估是在数组成员的0初始化之前或之后完成的。
编辑:缺陷报告#208中存在数组元素的未指定初始化顺序的情况。情况不同,因为在DR示例中,单个元素有两个初始化器。
int a [2] = { f (0), f (1), [0] = f (2) };
It was the intention of WG14 that the call f(0) might, but need not, be made when a is initialized. If the call is made, the order in which f(0) and f(2) occur is unspecified (as is the order in which f(1) occurs relative to both of these). Whether or not the call is made, the result of f(2) is used to initialize a[0].