CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Array addressing different returned values

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
komandor



Joined: 31 Jul 2018
Posts: 1

View user's profile Send private message

Array addressing different returned values
PostPosted: Tue Jul 31, 2018 6:01 am     Reply with quote

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: 19548

View user's profile Send private message

PostPosted: Tue Jul 31, 2018 6:50 am     Reply with quote

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: 19548

View user's profile Send private message

PostPosted: Mon Aug 06, 2018 3:53 am     Reply with quote

Just FYI, have checked back and this was fixed in 4.118.
jeremiah



Joined: 20 Jul 2010
Posts: 1357

View user's profile Send private message

PostPosted: Sat Aug 18, 2018 9:25 am     Reply with quote

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".
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group