CodeWarrior 6.3 for HCS08.
Why do I get warning C2705 in the division statement below?
static void Do_SM_PostStateTasks(void)
{
int8_t A;
int8_t B;
int8_t C;
A = 10;
B = 20;
C = (A / B); // <---- WARNING HERE - WHY
SM.StateTimer = C;
}
Hi Anders,
the division requires integral promotion in C language. So both A and B will be expanded to int, with an int division. The result is again int (16bit on the HCS08) and then gets assigned to an 8bit variable C. At that point you will loose the upper 8 bit, and that's what the warning is about.
I hope this helps,
Erich
Thank you Erich,
for ending my head scratching session.
Much appreciated,
Anders