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 support@ccsinfo.com

Data type PIC24

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



Joined: 27 Jul 2013
Posts: 79

View user's profile Send private message

Data type PIC24
PostPosted: Thu Aug 21, 2014 12:07 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Aug 21, 2014 1:35 pm     Reply with quote

No, it's not a bug. PCD is different.
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Thu Aug 21, 2014 2:14 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 12:41 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 1:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 3:13 am     Reply with quote

Apparently char is also being defined as signed.
It took me hours to debug my CRC code Mad .
If CCS can't follow ANSI C the least they could do is to keep things standardized.
Ttelmah



Joined: 11 Mar 2010
Posts: 19342

View user's profile Send private message

PostPosted: Fri Aug 22, 2014 9:09 am     Reply with quote

Remember you can also just add:

#type unsigned

To change the default.
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