Posted on May 17, 2011 at 15:08 Hi,
the compiler behaviour is correct: in your first example, the C language requires that the result of 16x16 is 16 (bits) and only afterwards it is converted to long (32 bits) because you assign the result to a long variable.
In your second example (casting), the C would require to promote both operands to long, make a long multiplication (32x32) and then assign the result to the long variable, but the compiler detects a possible optimization (the operands are 16 bits) and therefore performs 16x16=32, that is what you want.
C rules are a bit ''difficult'' when it comes to mixing different types...
Regards,
Luca (Cosmic)