This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Array indexing with unsigned int

C251 v3.12

The C251 compiler does not handle arithmetic for array indices consistently. Consider

char tt[30] ;
char test ;
unsigned char aaa = 27 ;
unsigned int  bbb = 27 ;

test = tt[aaa - 20] ;
test = tt[bbb - 20] ;
The assembly code for the index using the unsigned char (aaa) has "-20" in its address construction. The assembly code for the index using the unsigned int (bbb) has "+65576" in its address construction. OOPS!
With the 8051's 16-bit address, this is no problem, but when using far addressing on the 251 you end up in different memory banks. int and char index variables work correctly like the unsigned char.

0