I don't understand why theses following operations could be OK or NOK when i run program with simulator.
void main()
{
long number;
number = 1000*33; //The result is -32536
}
void main()
{
long number;
number = 1000*3.3*10; //The result is 33000
}
Do you have any explanations? In fact i would like do a big operation what king of type number declaration i will use?
Thanks a lot
david
Hello
According to the standard an ANSI C compiler will evaluate expression like 1000*33 on an int (16-bit) value and then result will be signed extended to long.
You need to tell the compiler the expression should be evaluated on 32-bit value.
In this purpose use the L prefix in one of the operant.
Your expression should be written 1000L * 33
This is compliant with ANSI C language definition.
CrasyCat