block-scope static const objects don't get initialized, e.g.
int f(void)
{
static const int a;
static const int b;
return a + b;
}
Might return something other than 0. However, both a and b are static, and should thus get implicitly initalized to 0 at program startup (see 6.7.9p10 in the C2X draft N2479 - AFAIK the same holds in all earlier C standards).
This can easily be reproduced by removing the #if 0 in bug-3040.c regression test.
From the asm code, it looks as if space for these is allocated, as for initalized const variables, but no value is there, i.e. we see just something like
to be placed somewhere in read-only memory.
This also affects other const objects that should be default-initialized, and still happens in SDCC from current trunk:
Last edit: Philipp Klaus Krause 2022-08-30
Fixed in [r13674].
Related
Commit: [r13674]