Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
why adding #define contsants for initializing a const is breaking rule 10.3 ?
#6
In the following discussion, it is assumed that uint16_t is an unsigned integer type of size 16 bits and to make the discussion easier it is assumed that "unsigned short" is also 16 bits.

Appendix D.6 shows that 556U and 420U are given the essential type of essentially unsigned short.

Appendix D.7 for + on essentially unsigned types says:
Code:
Operations subject to the  usual arithmetic conversions( * / % + - & | ^ )
2. Else if the operands are both essentially unsigned then:
   2.1 If the expression is an integer constant expression then the
       essential type of the result is the UTLR of the result;
Therefore the essential type of "556U + 420U" is that of "essentially unsigned short"since 976 fits within a 16-bit short.

There are no violations of rule 10.3 as all three assignments are from "essentially unsigned short" to "essentially unsigned short".
Posted by and on behalf of the MISRA C Working Group


Messages In This Thread

Forum Jump:


Users browsing this thread: 5 Guest(s)