/* >>>------------------------------------------------------------ * * File: rule_10.6.c, Module: M2CM-3.2-QAC-8.1.2 * * RULE 10.6 (Required): * A "U" suffix shall be applied to all constants of unsigned * type. * * Implemented by message: * 1281 Integer literal constant is of an unsigned type but does * not include a "U" suffix. * * <<<------------------------------------------------------------ */ /* PRQA S 0339,2982,3112,3205 ++ */ #include "misra.h" #include "m2cmex.h" /******************************************************************* ISO 6.1.3.2 RULES: ================== The type of an integer constant is the first of the corresponding list in which its value can be represented. UNSUFFIXED DECIMAL: int, long, unsigned long UNSUFFIXED OCTAL OR HEX: int, unsigned int, long, unsigned long SUFFIXED WITH U: unsigned int, unsigned long SUFFIXED WITH L: long, unsigned long SUFFIXED U and L: unsigned long The table below shows the type of an integer constant of various magnitudes in different formats. Types shown are for a 16bit int. ------------------------------------------------------------------------ Decimal/Hexadecimal Value |UNSUFFXD|UNSUFFXD|SUFFIXED|SUFFIXED|SUFFIXED| | DECIMAL| HEX/OCT| WITH U| WITH L| WITH UL| ------------------------------------------------------------------------ 32767 / 0x7FFF | SI | SI | UI | SL | UL | 32768 / 0x8000 | SL | UI | UI | SL | UL | 65536 / 0x10000 | SL | SL | UL | SL | UL | 2147483647 / 0x7FFFFFFF | SL | SL | UL | SL | UL | 2147483648 / 0x80000000 | UL | UL | UL | UL | UL | ------------------------------------------------------------------------ The following examples assume that int is configured as 16 bits. *******************************************************************/ extern S16 test_1006( void ) { /* Decimal */ 2147483648; /* MISRA Violation - unsigned long */ 4294967295; /* MISRA Violation - unsigned long */ 2147483648L; /* MISRA Violation - unsigned long */ 4294967295L; /* MISRA Violation - unsigned long */ /* Hexadecimal */ 0x8000; /* MISRA Violation - unsigned int */ 0xFFFF; /* MISRA Violation - unsigned int */ 0x80000000; /* MISRA Violation - unsigned long */ 0xFFFFFFFF; /* MISRA Violation - unsigned long */ 0xFFFFFFFFL; /* MISRA Violation - unsigned long */ 0x80000000L; /* MISRA Violation - unsigned long */ /* Octal */ 0100000; /* MISRA Violation - unsigned int */ 0177777; /* MISRA Violation - unsigned int */ 020000000000; /* MISRA Violation - unsigned long */ 037777777777; /* MISRA Violation - unsigned long */ 020000000000; /* MISRA Violation - unsigned long */ 037777777777L; /* MISRA Violation - unsigned long */ return 0; }