Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 10.5, shift left operator example
#4
I tried to give you one example where it would happen, based on the one from MISRA.

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>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)