View previous topic :: View next topic |
Author |
Message |
haxan7
Joined: 27 Jul 2013 Posts: 79
|
Data type PIC24 |
Posted: Thu Aug 21, 2014 12:07 pm |
|
|
int8 and short declares as signed instead of unsigned for PIC24, compiler 5.xx, is this a bug or am I missing something. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Aug 21, 2014 1:35 pm |
|
|
No, it's not a bug. PCD is different. |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu Aug 21, 2014 2:14 pm |
|
|
Hi,
Interestingly, here is what page 28 of the PCD manual says:
Quote: |
All types, except float char , by default are unsigned; however, may be
preceded by unsigned or signed (Except int64 may only be signed) .
|
John |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 22, 2014 12:41 am |
|
|
It has been warned about on many occasions here.
Also if you select ANSI, it switches to signed, even on PCM/PCH.
The simplest 'test', is to compile something like this, and run it in MPLAB SIM for example:
Code: |
int8 u;
for (u=0;u<129;u++)
delay_cycles(1);
|
On PCM/H, it merrily stops when u gets to 129, but on PCD, generally it'll never exit, with the number being treated as -1, when it passes 127.
It's been the case for as long as I can remember, and the 'readme.txt' for some of the V4 compilers did point this out.
The V4 manual, has the line (for PCD):
"signed Data can be negative or positive. This is the default data type if not specified."
In the V5 PCD manual, if you look at the older release (till about March this year), you have (under the data types table):
"Note: All types, except char, by default are signed; however, may be preceded by unsigned or signed (Except int64 may only be signed) ."
However the latest release has lost this section. Duh....
So it is a bug, with the manual....
Generally, it is much safer, especially when working 'between' chips (PCH - PCD etc.), to be explicit, load 'stdint.h', and then use int8_t, and uint8_t for signed and unsigned, or setup the types yourself with a '#type' statement (though this brings the caveat, that some of the supplied drivers may not like you changing the defaults.... |
|
|
haxan7
Joined: 27 Jul 2013 Posts: 79
|
|
Posted: Fri Aug 22, 2014 1:25 am |
|
|
I thought I was being clever by defining all the data types as int8 and int16.
Wasted a lot of time in debugging, and had to change all the data types with stdint typedefs. |
|
|
haxan7
Joined: 27 Jul 2013 Posts: 79
|
|
Posted: Fri Aug 22, 2014 3:13 am |
|
|
Apparently char is also being defined as signed.
It took me hours to debug my CRC code .
If CCS can't follow ANSI C the least they could do is to keep things standardized. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Fri Aug 22, 2014 9:09 am |
|
|
Remember you can also just add:
#type unsigned
To change the default. |
|
|
|