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

signed ints?

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



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

signed ints?
PostPosted: Tue Aug 02, 2005 2:33 pm     Reply with quote

Hi all,

When defining an int in ccs, is it just capable of taking values from 0-255? Is it not able to take negative numbers? What would the value of the following be:

int x;

x = -8;

Would that give you zero or -8 for x?

Thanks!
newguy



Joined: 24 Jun 2004
Posts: 1907

View user's profile Send private message

PostPosted: Tue Aug 02, 2005 2:41 pm     Reply with quote

An int and a signed int store numbers the same - the difference is in how the variables are treated.

If I did this:

int x = 10, y = -1;

x would contain decimal 10, or hex 0x0A. y would contain decimal 255, or hex 0xff.

If I had defined both x & y as being unsigned int, their contents would be exactly the same. The only difference would be in doing arithmetic or in doing tests. For instance, if they were both defined as ints, then:

if (y < x) would never evaluate to true, since y = 255, and x = 10.

If they were both defined as signed ints, then if (y < x) would evaluate to true.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 02, 2005 3:21 pm     Reply with quote

In CCS, integer declarations default to unsigned values. This is
different from normal C. To declare an unsigned 8-bit integer,
you can do this:

int my_value;
or
int8 my_value;


In CCS, to declare a signed 8-bit integer, you have to
explicitly declare as such. Example:

signed int my_value;
or
signed int8 my_value;
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