Can a (C/C++) array initialization reference itself?

前端 未结 4 989
南方客
南方客 2021-01-01 10:00

I was wondering about an initialization of the following form:

int  array[] = {
v - 1,
array[0] + 1
} ;

In the initialization of the second

4条回答
  •  青春惊慌失措
    2021-01-01 10:23

    As far as I can see, this is not well defined. The standard (C++11, 8.5.1/17) specifies that "The full-expressions in an initializer-clause are evaluated in the order in which they appear", but I can't see anything that requires each aggregate element to be initialised from the result of its initializer-clause before the next is evaluated.

提交回复
热议问题