View previous topic :: View next topic |
Author |
Message |
komandor
Joined: 31 Jul 2018 Posts: 1
|
Array addressing different returned values |
Posted: Tue Jul 31, 2018 6:01 am |
|
|
Hello!
I noticed problem, I have a table declared:
Code: | int16 const crctab[256]={0x00 0x1D 0x3A.....0xFE 0xD9 0xC4}; |
I declared it as int16 and now
Code: | int8 index=160;
putc(crctab[index]); |
for index values from 0 to 127, correct array elements are retrieved, for values 128 to 255, the array values are displayed from the beginning, i.e. for index = 10 I get the same value as for index = 138.
what's interesting when I do something like this:
Code: | int8 const index=160; |
it works correctly now
and when I change it from int16 to int8
Code: |
int8 const crctab[256] |
it works correctly for both cases.
I would like to know why this is happening.
Im using CCS V4.114, PIC16F628A |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue Jul 31, 2018 6:50 am |
|
|
6 year old compiler.....
There were issues with arrays that crossed memory pages on many of the older compilers.
The calculations only used an int8 for the offset. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Mon Aug 06, 2018 3:53 am |
|
|
Just FYI, have checked back and this was fixed in 4.118. |
|
|
jeremiah
Joined: 20 Jul 2010 Posts: 1355
|
|
Posted: Sat Aug 18, 2018 9:25 am |
|
|
Just wanted to toss in that if you declare your index as int8 as the OP did, then the highest value it is supposed to do on a compiler rev that defaults to signed is +127. After that it wraps around to negative numbers, and depending on how the index math is done, that can lead to weird results. The OP should declare the index as "unsigned int8".
I find it is always best to specify "signed" or "unsigned". |
|
|
|