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

Is this a bug for Long variable?

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







Is this a bug for Long variable?
PostPosted: Mon Sep 27, 2004 1:53 am     Reply with quote

I have program like this :

long myMoney;
long yourMoney;

myMoney=10000;
yourMoney=Mymoney + 60000;

Why yourMoney <> 70000 ?
but it is 4XXX

Is it bug in CCS?
Ttelmah
Guest







Re: Is this a bug for Long variable?
PostPosted: Mon Sep 27, 2004 3:23 am     Reply with quote

Aman wrote:
I have program like this :

long myMoney;
long yourMoney;

myMoney=10000;
yourMoney=Mymoney + 60000;

Why yourMoney <> 70000 ?
but it is 4XXX

Is it bug in CCS?

No.
It is a bug in your thinking...
A 'long', is a 16bit integer. Maximum value 65535. Your addition will result in 4464, since the arithmetic has overflowed. If you need to deal with numbers above 65535, you have to select an int32.
This is why I don't like/use the 'long' designation. Instead use int8, int16, and int32, which makes it plain to you, and anyone latter trying to use your code, what length the actual storage is. Unfortunately, in original 'C', an 'integer' was defined to suit the processor, and it's length varies with the processor, and the same applies to the 'long' version...

Best Wishes
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