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

Variable issues

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



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

Variable issues
PostPosted: Mon Mar 10, 2014 10:51 pm     Reply with quote

I tried to find something in the topics specific to my issue!

CCS C 4.130
PIC24HJ128GP502;

I'm having an issue with variables!
Code:

unsigned char *cDat; // this is pointing to a bunch of memory else where
unsigned short *value;

*value = pDat[0]<<8;
*value |= pDat[1];

This results in some very strange data.
Both pdat[0] and [1] are values of 255

so the value >should< be 65535.

But its not, it seems to be coming up with something else. Still 16bit but not the right value.

When i try
Code:

unsigned char *cDat; // this is pointing to a bunch of memory else where
unsigned short *value;

*value = (unsigned int16)pDat[0]<<8;
*value |= (unsigned int16)pDat[1];

Everything works fine...

Now i understand the need for the (unsigned int16) stuff, but if i had to do that with all the variables, its going to be a very long night.

I'm using stdint.h and
Code:
#type signed

I can't seem to figure this out...

Thanks guys :D
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 10, 2014 11:14 pm     Reply with quote

[ugghh]

think i found away, make16........ but i didn't want to go through all that code changing this............ DAMN IT!
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Tue Mar 11, 2014 9:01 am     Reply with quote

Just as a note, a "short" is a 1 bit variable. I'm not sure you want that and you might be corrupting some of your variables (not sure how a dereferenced pointer to a 1 bit variable works in assignment). For CCS, I would suggest sticking with int1, int8, int16, int32, etc. instead of using short, long, etc. Much more portable between chips (if you ever need to).
neochrome32



Joined: 09 Jun 2013
Posts: 153

View user's profile Send private message Visit poster's website

PostPosted: Wed Mar 12, 2014 1:33 am     Reply with quote

due to the way i wrote this original on the pc, short is now 8

deftype unsigned char short

i set #type short=8, int=32, long=32
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