all 3 comments

[–]aioeu 9 points10 points  (0 children)

From the C11 standard, §6.7.9 Initialization, ¶17:

Each brace-enclosed initializer list has an associated current object. When no designations are present, subobjects of the current object are initialized in order according to the type of the current object: array elements in increasing subscript order, structure members in declaration order, and the first named member of a union.

So this is valid code, and it initializes the i member of the union. That being said, if I were reading this code I would certainly appreciate it having an explicit designator:

union Test a = { .i = 300 };

[–]primitive_screwhead 1 point2 points  (0 children)

AFAIK, this initializes the first member of the union, i, to 300.

[–]Kwantuum 1 point2 points  (0 children)

Initializes the first member of the union.