#204 Global scoping is getting lost

closed-fixed
Johan Knol
5
2013-05-25
2001-10-31
Scott Dattalo
No

unsigned char char0 = 0;
unsigned char char1 = 0;
unsigned char char2 = 0;
unsigned char i = 0;

void c2(void)
{

char2 = char0+1;
}

void c1(void)
{
char2 = 9;

for(i=0;i<4;i++) {
c2();
char1=char2;
char0+=char1;

}
}

---------
The scope of char2 is getting lost in the assignment
char1=char2; statement.

e.g.:
sdcc -c -mmcs51 t.c

<snip>
; t.c 28
; -----------------------------------------
; function c1
; -----------------------------------------
_c1:
; t.c 30
mov _char2,#0x09
; t.c 32
mov _i,#0x00
mov r2,#0x09
00101$:
clr c
mov a,_i
subb a,#0x04
; Peephole 108 removed ljmp by inverse jump logic
jnc 00105$
00109$:
; t.c 33
push ar2
lcall _c2
pop ar2
; t.c 34
mov _char1,r2
; t.c 35
mov a,_char1
add a,_char0
mov _char0,a
; t.c 32
inc _i
; Peephole 132 changed ljmp to sjmp
sjmp 00101$
00105$:
ret

<snip>
At t.c 34, the assignment of char1=char2 is actually
being generated as char1=r2, which is scoped locally to
c1(). I'm fairly certain that it's an iCode problem
because I saw this first in the PIC Port.

Scott

Discussion

  • Johan Knol
    Johan Knol
    2001-10-31

    Logged In: YES
    user_id=63512

    fixed in SDCCloop.c:1.19

     
  • Johan Knol
    Johan Knol
    2001-10-31

    • milestone: --> fixed
    • assigned_to: nobody --> johanknol
    • status: open --> closed-fixed