Sven Kopacz

CW 6.1 for MCF51AC256: Why do bitwise operations default to an INT result?

Discussion created by Sven Kopacz on Aug 19, 2008
Latest reply on Aug 25, 2008 by Sven Kopacz
Hello,

I am currently porting C code to the 51AC256.
I get plenty of warnings about "implicit conversions from int to unsigned  char" in cases like this:

----
unsigned char a, b;
...
a=b & 0x0f;
----

Just assigning "a=0x0f" causes no warning, so it is not the constant but the result of the bitwise AND, that is treated as an integer by the compiler. However to my understanding of C this should not be the case, instead it should default to the common operands type. So since both are unsigned char, the result should be as well.

Besides working over all the code like "a=(unsigned char)b & 0x0f", is there any option I could turn on/off to have the compiler think of the result's type as a type matching the operands?

I know I could turn off the warnings, however this is not an option since I'd lose the serious warnings as well.

Regards,
 Sven

Outcomes