1: Sample code that reproduces the problem.
Save as resumption.c.
struct I { int member; };
struct S {
union { struct { struct I x; struct I y; }; int z; };
struct I next[2];
};
#ifdef LOCAL
void test(void)
{
struct S object = {
{ { {1}, {2} } },
{ [0] = {3}, [1] = {4} }
};
(void)object;
}
#else
struct S object = {
{ { {1}, {2} } },
{ [0] = {3}, [1] = {4} }
};
#endif
2: Exact command used to run SDCC on this sample code.
sdcc -mz80 --std-c11 -S resumption.c -o resumption.asm
3: SDCC version tested.
SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/r4k/r5k/r6k/sm83/tlcs90/ez80/z80n/r800/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15/mos6502/mos65c02/huc6280/f8/f8l TD- 4.6.4 #17200 (Linux)
published under GNU General Public License (GPL)
Unmodified official snapshot, retested on Linux x86_64 on 18 November 2026.
4: Observed and expected behaviour.
resumption.c:18: error 202: Invalid designator for designated initializer
resumption.c:20: error 68: too many initializers
resumption.c:16: warning 147: excess elements in scalar initializer after 'object'
resumption.c:17: warning 334: excess braces in initializer
resumption.c:16: warning 147: excess elements in scalar initializer after '__xinit_object'
The compiler exits with status 1. The first outer entry initialises the anonymous union through its anonymous structure. The second initialises next. The program should compile successfully with object.x.member == 1, object.y.member == 2, object.next[0].member == 3 and object.next[1].member == 4.
5: Additional checks.
The automatic-storage variant is also rejected when -DLOCAL is added to the command above. GCC accepts both variants with -std=c11 -pedantic-errors -fsyntax-only. The rejections were also reproduced on STM8, MCS51 default and PDK14 with r17200.
Compiler Explorer uses the same source and SDCC trunk with -mz80 --std-c11. The CE build tested was SDCC 4.6.4 #17204 (Linux), distinct from the local r17200 retest.
Possibly related to [bugs:#3584] (anonymous-member initialisation semantics) and [bugs:#3393] (anonymous-union initialisation). These exact reproducers were not found in those reports.
Bugs: #2948
Bugs: #3393
Bugs: #3584
Wiki: SDCC 4.7.0 Release
The candidate patch attached to [bugs:#2948] includes a fix and regression test for this bug. Please review the patch there.
Related
Bugs: #2948