View previous topic :: View next topic |
Author |
Message |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
char not evaluating properly? |
Posted: Mon Dec 10, 2012 1:55 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Mon Dec 10, 2012 2:24 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Dec 10, 2012 3:40 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Mon Dec 10, 2012 3:47 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Mon Dec 10, 2012 8:07 am |
|
|
Yes. They do not explicitly 'say', but default to all the integer types being 'signed'. Being explicit is always much safer....
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
|