sdcc sometimes stores string constants extremly
inefficiently. It seems all ports are affected (I tried
Z80 and PIC14).
I compiled with
sdcc -c -mz80 --std-c99
sdcc -c -mpic14 -p16c745 --std-c99
sdcc --version gives
2.6.0 #4309 (Aug 16 2006) (UNIX)
The follwing small program shows the problem:
const char test1 = "testtest1";
const char test2 = "testtest2";
const static char test3 = "testtest3";
sdcc generates optimal code for test1. For both test2
and test3 suboptimal code is generated.
The pic14 port generates a movlw and a movwf for every
byte of test2 or test3.
The z80 port generates 6 ld instructions, one add and
one adc for every byte of test2. It generates two ld
instructions per byte of test3.
All of the string constants used could be stored as
efficiently as test1, since they are constants and thus
could reside in ROM. Now the generated code is a waste
of RAM, ROM and runtime.