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

char not evaluating properly?

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



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

char not evaluating properly?
PostPosted: Mon Dec 10, 2012 1:55 am     Reply with quote

If I replace the int16 with char it is an endless loop as the for loop with i does not quit at 0x80 as expected but just keep on incrementing until rollover. Am I missing something regarding types or maybe compiler error. I know this code not optimised but busy with it to write to GLCD with driver not on forum yet.

Using version 4.140

Code:

void glcd_DispClr() {
  int16 i,j,t;
 
  for(j=0;j<8;j++){
      t=j*8;
    for(i=0; i<128; i++) {             // 16 bytes per line 64 lines
      glcd_SetRowCol(t,i);
      glcd_WriteData(0,1);                // write empty byte
    }
  }     
}


Thanks Alan
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Mon Dec 10, 2012 2:24 am     Reply with quote

What chip?.
If you are using a PIC24, then the default type is 'signed', not unsigned. A signed char, can only support 0..127.

Best Wishes
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Dec 10, 2012 3:40 am     Reply with quote

In general it is bad practice to use the char type for counters, use a type that better represents it's purpose like int8, int16, etc. It is possible that at a lower level these types do map onto a basic compiler type like char, but then at least from your code it is more clear what your intentions are.
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Mon Dec 10, 2012 3:47 am     Reply with quote

Sorry forgot. PIC24.

According to CCS docs char are unsigned, but obviously I missed the part where it states that char are signed for PIC24.

Have already changed it to unsigned int8 which as expected works.

Thanks for your replies.
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Mon Dec 10, 2012 8:07 am     Reply with quote

Yes. They do not explicitly 'say', but default to all the integer types being 'signed'. Being explicit is always much safer....

Best Wishes
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