the following code:
signed char sc = ~0xFC;
unsigned char uc = ~0xFC;
when compiled gives me the following warnings:
integer conversion resulted in truncation
integer conversion resulted in truncation
- why do i get these warnings
- how do i write my code, so that i dont get these warnings (without using #pragmas)
thanx,
i’m using IAR Compiler for 8051,
do you get similar warnings when compiling using other compilers?
In C, arithmetics are performed at least at the size of
int. That means,~0xFCwill return anint. Even more, this value is0xFF03which is way beyond the range ofchar(signed or not).Therefore, the assignment will give the two warnings. You could try
to see if the compiler knows that the result is within the range of
char(gcc won’t complain after adding the& 0xFF). You could also try to add an explicit cast:or, as the value can be easily computed, why not just