Yes, every compiler promotes those operands or it doesn't conform to ISO C. Try to run this code on any C compiler and you will see for yourself:
unsigned char x, y;
printf("%d", sizeof(x+y));
However, the compiler may of course optimize the code how much it wants as long as it doesn't change the meaning of it. This is the case in your S08 example.
The reason you get a warning on Codewarrior is because it is more picky than other compilers, which is a good thing. An embedded compiler needs to be extra aware of things like implicit typecasts, since the code is much more likely to be ported, as well as more likely to steer safety-critical applications, compared to for example code written for a PC.
And yes, the integer promotion rules are quite illogical, just as the rest of the C language. But they exist for a reason, consider this situation:
unsigned char x = 255;
unsighed char y = 255;
if( (x+y) > 255)
{
/* do something */
}
Because of the integer promotion rules, the expression is evaluated correctly. If there was no promotion, x+y would have been 254 and the program wouldn't work as expected.
Message Edited by Lundin on
2008-08-25 12:48 PM