On 12/20/2016 01:52 PM, Aldy Hernandez wrote:

int array[10] = { array[3]=5, 0x111, 0x222, 0x333 };

(gdb) x/4x &array
0x601040 <array>:       0x00000005      0x00000111      0x00000222
0x00000005

That is, the array[3]=5 overwrites the last 0x333.  I would expect that...

That may be wrong. Using the 4431 draft, [8.5.4]/4 says 'Within the initializer-list of a braced-init-list, the initializer-clauses, including any that result from pack expansions (14.5.3), are evaluated in the order in which they appear.' It goes on to mention that there are sequence points, plus that the ordering holds regardless of the semantics of initialization.

So by my reading, the effects of the above list are:
a) assign 5 to array[3]
b) assign 5 to array[0] -- consume the first initializer
c) assign x111 to array[1] -- consume the second initializer
d) assign 0x222 to array[2] -- consume the third initializer
e) assign 0x333 to array[3] -- consume the fourth intializer,
                               overwrite #a

nathan
--
Nathan Sidwell

Reply via email to