When I initialize the array below all the output looks ok except for values[3]
. For some reason values[3]
initialized as values[0]+values[5]
int values[10] = {
[0]=197,[2]=-100,[5]=350,
[3]=values[0] + values[5],
[9]= values[5]/10
};
edit:
The ISO C99 standard, section 6.7.8 (Initialization) specifies that
The initialization shall occur in initializer list order, each initializer provided for a particular subobject overriding any previously listed initializer for the same subobject;132) all subobjects that are not initialized explicitly shall be initialized implicitly the same as objects that have static storage duration
But as Shafik pointed out, the evaluation order doesnt have to match the initialization order
Which means values[0] + values[5]
may read garbage values from:
values[0]
values[5]
(this is what happen in your case)