Dear SDCC Team,
during porting the USB M-Stack to my PIC 18F27J53 I figured out that the compiler do strange things in functions, where parameter of this function shall be copied with previously call of a preconfigure function. I made a simple "test.c" to show the problem in the produced assembler file. After calling setName() I expect that the pointer shows to {pNameA=>"alfred", pNameB=>"bert", pNameC=>"carly", pNameD=>NULL} but all pointer are then initialized to NULL. A look to the compiled test.asm shows clear, that the function resetName() is called at the end of the code, therefore all copied values are cleared to NULL. Why it is called at the end?
I hope I havn't made stupied things here:-)
I havn't test the newest compiler, maybe this problem is already known?
best reagrds
Tweny68
Used SDCC:
SDCC : mcs51/z80/z180/r2k/r3ka/gbz80/tlcs90/ds390/pic16/pic14/TININative/ds400/hc08/s08/stm8 3.4.0 #8981 (Apr 5 2014) (Linux)
published under GNU General Public License (GPL)
How I called SDCC:
sdcc -V --std-c99 --use-non-free -I. -mpic16 -ppic18f27j53 -DSDCC_PIC18F27J53 -D_18F27J53 -DUSE_FLOATS -c -o test.o test.c
<begin of="" test.c=""></begin>
static char NameA[10] = {"anna"};
static char NameB[10] = {"berta"};
static char NameC[10] = {"calotta"};
static char NameD[10] = {"dora"};
static char * pNameA = NameA;
static char * pNameB = NameB;
static char * pNameC = NameC;
static char * pNameD = NameD;
static void resetName(void);
void setName(char * p1, char * p2, char * p3){
resetName();
pNameA = p1;
pNameB = p2;
pNameC = p3;
}
void resetName(void){
pNameA = NULL;
pNameB = NULL;
pNameC = NULL;
pNameD = NULL;
}
void changeName(void){
setName("alfred","bert","carly");
/**
expected pointer assignments:
pNameA => "alfred"
pNameB => "bert"
pNameC => "carly"
pNameD => NULL
Bug: But it is:
pNameA => NULL
pNameB => NULL
pNameC => NULL
pNameD => NULL
/
}
<end of="" test.c=""></end>*