Forum : 8051
Original Post
Post Information | Post |
---|---|
October 24, 2007 - 8:36pm
|
Compile these with ANSI integer promotion off. In the 3rd function, the compiler ignores (int). This happens only when the cast is on the last byte of the constant expression. int worksOK(void) int alsoOK(void) int butThisIsBad(void) I've posted a previous problem which occurs with this compiler option. Raisonance' recommendation was to not use the ANSI-integer-off option. This compiler option is useful; it shrinks 8-bit code quite a bit; its my default for new code development. So I hope you address this and other issues particular to this option. regards Steven Pruzina |
Hi Steven,
The Raisonance Compilers follow the ANSI standard for the order of evaluation.
So in your third function what you really feed into the compiler is:
return (0xFF + 0x0A) + (int)0x0D;
(This is because the '+' binary operator groups from left to right.
As you devalidated ANSI promotion, what the compiler does is:
return (char)(0xFF + 0x0A) + (int)0x0D;
And (char)(0xFF + 0x0A) resolves to (char)(0x09).
I hope this helps,
Bruno
Hi Bruno
Thanks for explaining this. There's always more to learn.
regards Steven Pruzina