View previous topic :: View next topic |
Author |
Message |
neochrome32
Joined: 09 Jun 2013 Posts: 153
|
Variable issues |
Posted: Mon Mar 10, 2014 10:51 pm |
|
|
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
I can't seem to figure this out...
Thanks guys :D |
|
|
neochrome32
Joined: 09 Jun 2013 Posts: 153
|
|
Posted: Mon Mar 10, 2014 11:14 pm |
|
|
[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: 1349
|
|
Posted: Tue Mar 11, 2014 9:01 am |
|
|
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
|
|
Posted: Wed Mar 12, 2014 1:33 am |
|
|
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 |
|
|
|