Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA2004-12_7-3 - Underlying type of LHS operand
#6
I was assuming that unsigned int is at least 16 bits wide. The C standard doesn't permit it to be any narrower than this (see C99 Sections 6.2.5 and 5.2.4.2.1).

So, the left shift and the addition are both performed in a type that is at least 16 bits wide. It it guaranteed that the results of both operations will fit in those 16 (or more) bits. It's also guaranteed that all bits numbered 16 and higher will be 0 so your compiler can select 16-bit instructions if it's able to and if doing so would be beneficial. That means you shouldn't lose out on efficiency and will gain portability.
<t></t>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)