Hello
The ANSI C standard tells that arithmetic on constants is perform on an int (16-bit for HC08 or HC12 compiler) when the constant can be encoded on an int (Which is the case here).
You have to cast one of the operator (usually the first one) to get it done on 32-bit.
Note that ANSI C provides an alternate way to tell the compiler to interpret an integer constant as a long.
Writing your macro as follows will ensure the preprocessor evaluates it as 640:
#define D_GAIN ((32L * 16 * 1000 )/ (50 * 16))
The L stands for long. You can also use UL for unsigned long.
I hope this helps.
CrasyCat
Apparently, no compiler I have ever used (and that's at least 10) has been compliant with ANSI C because I have never run across this before. Is there a way I can turn this feature off because I have a LOT of legacy code here that won't build correctly without this modification and loss of portability. If not, how would I get it to use floating point for things like this...
#define D_GAIN ((32 * 16 * 1000 )/ (50 * 16))
EXTERN const uWord D_Gain (uWord)(0.651 * D_GAIN);
In this case, I expect the preprocessor to use floating point and then truncate the value to 16 bits resulting in a const value of 416. Do you know where I can find this kind of information in the Codewarrior docs because I can't find it anywhere?