XaviDCR92 / stm8-dce-example

Demonstration of link-time dead code elimination for the STM8 using SDCC and GNU binutils
11 stars 2 forks source link

Initialization of static variables #5

Open MarrekNozka opened 2 years ago

MarrekNozka commented 2 years ago

I created this function in main.c:

uint16_t foo(void) {
    static uint16_t x = 20;
    return x += 91;
}

and I got this error message:

sdcc-gas src/main.c -DSTM8S208 -mstm8 --out-fmt-elf -c --debug --opt-code-size --asm=gas --function-sections --data-sections -Iinc/ -MM > obj/main.d
sdcc-gas src/main.c -DSTM8S208 -mstm8 --out-fmt-elf -c --debug --opt-code-size --asm=gas --function-sections --data-sections -Iinc/ -o obj/main.o
src/main.c:14: warning 126: unreachable code
obj/main.asm: Assembler messages:
obj/main.asm: Error: can't resolve `.text._main' {.text._main section} - `.Lmain_foo_17' {.text._foo section}
make: *** [Makefile:63: obj/main.o] Chyba 1
rm obj/main.d

What is the right way to initialize static variable? Thanks.