Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Further guidance on MISRA-C 2012 Rule 10.6
#1
MISRA-C 2012 D.3 states that UTLR/STLR rules are only applied to integer constant expressions for operators that explicitly specify this in D.7. D.7 further states that the essential type is the standard type unless otherwise listed and does not specify a non-standard essential type for sizeof.

Given the following example: 
Code:
typedef unsigned int uint32_t;
typedef unsigned short uint16_t;
extern uint16_t u16;
extern uint32_t u32;

extern void foo( void );
void foo( void ) {
    uint32_t case1 = (sizeof(uint32_t) + sizeof(uint32_t)) + u16; /*Case 1*/
    uint32_t case2 = u32 + u32 + u16; /*Case 2*/
    uint32_t case3 = sizeof(uint32_t) + (sizeof(uint32_t) + u16);/*Case 3*/
    uint32_t case4 = sizeof(uint32_t) + u16 + sizeof(uint32_t); /*Case 4*/
}

Which of the cases violates Rule 10.6 while providing the rationale?
Reply


Messages In This Thread
Further guidance on MISRA-C 2012 Rule 10.6 - by mshawa - 09-04-2024, 02:29 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)