24-02-2009, 10:14 AM
I tried to give you one example where it would happen, based on the one from MISRA.
This code will give incorrect result:
And this will fix it:
result_16 = ((uint8_t)(port > 6;
This code will give incorrect result:
Code:
#define MASK 0x01U
uint8_t port = 0x5AU;
uint16_t mode;
uint16_t result_16;
mode = ~MASK; /* here the programmer gets values in the upper byte without realizing it */
result_16 = ((port > 6; /* strange result */
And this will fix it:
result_16 = ((uint8_t)(port > 6;
<t></t>