/* >>>------------------------------------------------------------ * * File: rule_10.5.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 10.5 (Required): * If the bitwise operators ~ and << are applied to an operand of * underlying type unsigned char or unsigned short, the result shall * be immediately cast to the underlying type of the operand. * * Implemented by messages: * 4397 An expression which is the result of a ~ or << operation * has not been cast to its essential type. * * 4398 An expression which is the result of a ~ or << operation * has been cast to a different essential type category. * * 4399 An expression which is the result of a ~ or << operation * has been cast to a wider type. * * 4498 An expression which is the result of a ~ or << operation * has been converted to a different essential type * category on assignment. * * 4499 An expression which is the result of a ~ or << operation * has been converted to a wider essential type on * assignment. * * <<<------------------------------------------------------------ */ /* PRQA S 2982,3112,3203,3447 ++ */ #include "misra.h" #include "m2cmex.h" extern S16 test_1005( void ) { /* USING WITHOUT CASTING */ ~u8a & 0x5A5AU; /* MISRA Violation */ ~0x5Au & u8a ; /* MISRA Violation */ ~u16a & 0x5A5A5A5Au ; /* OK */ ~0x5A5Au & u8a ; /* OK */ /* CAST TO DIFFERENT TYPE CATEGORY */ (S8 )(~u8a); /* MISRA Violation */ (S16)(~u8a); /* MISRA Violation */ (S32)(~u8a); /* MISRA Violation */ (S8 )(~0x5A5Au); /* MISRA Violation */ (S16)(~0x5A5Au); /* MISRA Violation */ (S32)(~0x5A5Au); /* MISRA Violation */ /* CAST TO WIDER TYPE */ (U8 )(~u8a); /* OK */ (U16)(~u8a); /* MISRA Violation */ (U32)(~u8a); /* MISRA Violation */ (U8 )(~0x5A5Au); /* OK */ (U16)(~0x5A5Au); /* MISRA Violation */ (U32)(~0x5A5Au); /* MISRA Violation */ /* ASSIGNMENT TO DIFFERENT TYPE CATEGORY */ s8a = ~u8a ; /* MISRA Violation */ s16a = ~u8a ; /* MISRA Violation */ s32a = ~u8a ; /* MISRA Violation */ s8a = ~0x5Au ; /* MISRA Violation */ s16a = ~0x5Au ; /* MISRA Violation */ s32a = ~0x5Au ; /* MISRA Violation */ /* ASSIGNMENT TO WIDER TYPE */ u8a = ~u8a; /* OK */ u16a = ~u16a; /* OK */ u8a = ~0x5Au; /* OK */ u16a = ~0x5A5Au; /* OK */ u16a = ~u8a ; /* MISRA Violation */ u32a = ~u8a ; /* MISRA Violation */ u16a = ~0x5Au ; /* MISRA Violation */ u32a = ~0x5Au ; /* MISRA Violation */ return 0; }