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

Better Way to Deal With Signed Int

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



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

Better Way to Deal With Signed Int
PostPosted: Mon Oct 09, 2006 6:02 pm     Reply with quote

Hello All,

I'm trying to store a value that can range from -1 to 65,535. It will arrive as a string and if the value is -1 then that is a flag otherwise it is a sequence number.

I can make a signed int32 to hold the value but it seems awfully wasteful. Is there a better way to skin the cat or am I making something of nothing? (btw, code space doesn't appear to be a problem yet.)

Thanks,

John
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 6:08 pm     Reply with quote

An elegant way would be to use a Structure containing an Int16 and a Short or boolean.
_________________
The search for better is endless. Instead simply find very good and get the job done.
jecottrell



Joined: 16 Jan 2005
Posts: 559
Location: Tucson, AZ

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 6:14 pm     Reply with quote

Ahhhh... thanks.

I had thought of using two variables, but thought that was kind of messy. Structures hadn't occured to me because I'm not that familiar with them... I guess it's time to make them my friend.

My general approach will be to check for a '-', and set that bit in the structure if necessary. Then parse the '-' character out of the string and then use the atol function to put the remainder of the srting in the int16 variable.

Sound about right.

Thanks,

John
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