Ttelmah Guest
|
Re: Is this a bug for Long variable? |
Posted: Mon Sep 27, 2004 3:23 am |
|
|
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 |
|