View previous topic :: View next topic |
Author |
Message |
SteveW
Joined: 27 Sep 2005 Posts: 25
|
Are long and int16 really the same? |
Posted: Tue Sep 27, 2005 3:28 pm |
|
|
According to the compiler manual, a long and an int16 are the same. Is this correct? Should long = int32? Typically a long is at least 32 bits.
Regards,
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Sep 27, 2005 3:38 pm |
|
|
Yes, in CCS a 'long' and 'int16' are the same.
Note that they are also both unsigned. |
|
|
SteveW
Joined: 27 Sep 2005 Posts: 25
|
|
Posted: Tue Sep 27, 2005 4:19 pm |
|
|
An int16 is unsigned? Wow, I would have never guessed that! Thanks, you just potentially save me a lot of headaches. So, for an integer of any type to be signed, it must explicitly be declared as signed? I have never seen a C compiler with this "feature". Is there a reason for it?
Regards,
Steve |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
SteveW
Joined: 27 Sep 2005 Posts: 25
|
|
Posted: Tue Sep 27, 2005 5:08 pm |
|
|
Interesting thread. I am now very happy that I started reading the manual before using the product. I would have never considered that a default int would be unsigned. I can live with this quirk, but how many more are there? Back to my reading.
Thanks again,
Steve |
|
|
Guest
|
|
Posted: Wed Sep 28, 2005 4:22 am |
|
|
It works the other way. I now code in CCS 99% of the time and try and use CCS "C" in the real world as well! |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Wed Sep 28, 2005 7:25 am |
|
|
It is always eye-opening for C++ programmers when I explain that I can't just add another flag to my old 16C54 code because I have already used the extra bits available in the Status register and adding another short would require a whole byte which I just don't have! _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Sep 28, 2005 8:21 am |
|
|
yes, keep hold of all those spare bits. Don't use a byte when a bit will do. |
|
|
|