From: Krishnendu C. <kri...@gm...> - 2011-02-21 16:15:55
|
Dear All, Consider the following code: --------------------------------------------- struct S1 { char a, b, c; }; typedef void (*foo_t)(void *arg); struct S2 { __xdata void *p; foo_t f1, f2, f3; }; void foo1 (void *arg) {arg;} void foo2 (void *arg) {arg;} void foo3 (void *arg) {arg;} void execute (__code struct S2 *s) { s->f1 (s->p); s->f2 (s->p); s->f3 (s->p); } void main (void) { static __xdata struct S1 s1; static __code struct S2 s2 = { &s1, foo1, foo2, foo3 }; execute (&s2); } --------------------------------------------- It is compiled with sdcc --model-large --stack-auto --std-c99 options. However it give the following link error: ?ASlink-Warning-Undefined Global '_s1' referenced by module 'main' I went into the assmebly code and found the error. ;------------------------------------------------------------ ;Allocation info for local variables in function 'main' ;------------------------------------------------------------ ;s1 Allocated with name '_main_s1_1_1' ;------------------------------------------------------------ ; main.c:25: void main (void) ; ----------------------------------------- ; function main ; ----------------------------------------- _main: ; main.c:37: s1.a = 1; mov dptr,#_main_s1_1_1 mov a,#0x01 movx @dptr,a ; main.c:38: execute (&s2); mov dptr,#_main_s2_1_1 ljmp _execute .area CSEG (CODE) .area CONST (CODE) _main_s2_1_1: .byte _s1,(_s1 >> 8) ; should be _main_s1_1_1 instead of s1 .byte _foo1,(_foo1 >> 8) .byte _foo2,(_foo2 >> 8) .byte _foo3,(_foo3 >> 8) .area XINIT (CODE) .area CABS (ABS,CODE) Hope I am correct. Krish |