sdcc -v: SDCC : mcs51/z80/z180/r2k/r2ka/r3ka/gbz80/tlcs90/ez80_z80/z80n/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8/pdk13/pdk14/pdk15 4.1.0 #12072 (MINGW64)
published under GNU General Public License (GPL)
sdcc compile command line: sdcc -mmcs51 --model-large -ooutput/ -Ic:/test -c ./main/main.c
sdcc link command line: sdcc -mmcs51 --model-large -ooutput/ -Ic:/test --xram-loc 0xFB00 --xram-size 640 -ooutput/firmware.hex output/main.rel
Running this code:
#include <stdio.h>
typedef struct
{
char a;
char b;
} abc;
abc def =
{
.a = 'A',
.b = 'B'
};
int main()
{
printf("%c\n", def.a);
printf("%c\n", def.b);
return 0;
}
Results in two garbage characters apearing in the terminal.
While running this code:
#include <stdio.h>
typedef struct
{
char a;
char b;
} abc;
const abc def =
{
.a = 'A',
.b = 'B'
};
int main()
{
printf("%c\n", def.a);
printf("%c\n", def.b);
return 0;
}
Results in A and B appearing as expected.
I don't see anything wrong with the generated code. If your microcontroller does not use P2 for the upper byte of the xram address, you'll need to supply an alternate definition for _XPAGE. See section 4.1.1 "pdata access by SFR" in the SDCC manual for some examples. Without the appropriate definition, the variables in xram will not be correctly initialized.
Yes, defining _XPAGE fixed the issue. Thank you.
Glad that it works as specified, after all. In that case we can close this as invalid.