SDCC 3.7.2 #10539 refuses to compile this:
struct s
{
union
{
int a;
int b;
};
int c;
int d;
};
struct s s2 = { .a = 0, .c = 3, .d = 4 };
Error messages:
test.c:13: warning 147: excess elements in struct initializer after 's2'
test.c:13: warning 147: excess elements in struct initializer after '__xinit_s2'
Philipp
This one looks fixed by patches/508. The reproducer from the report:
compiled to assembly against [r16747] and against [r16747] plus that patch set:
The two warnings are the visible symptom; the data is the reason it matters.
cwas taking the initializer meant for the member after it andd's 4 was dropped as excess, sos2came out{0, 0, 3}instead of{0, 3, 4}.What made it survive this long is probably that it never showed on mcs51: the defect is in the copy path (
printIvalStruct()), and mcs51 initializes globals with generated stores instead, which was already correct. Everything that emits an initializer image - z80, stm8, hc08, s08 - got the wrong bytes.The patch that does it is 0005 of the set, an initializer after a designated one belongs to the member following it (C11 6.7.9p17), and the walk must not undo the designated alternative. It carries
bug-3393-designated.c, which covers the designator shapes but not this exact one; happy to add the reproducer from this report to that test if you would like it recorded.Related
Commit: [r16747]
Last edit: Howard M. Harte 2026-08-02