Further guidance on MISRA-C 2012 Rule 10.6 - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21) +---- Forum: 8.10 The essential type model (https://forum.misra.org.uk/forumdisplay.php?fid=165) +---- Thread: Further guidance on MISRA-C 2012 Rule 10.6 (/showthread.php?tid=1681) |
Further guidance on MISRA-C 2012 Rule 10.6 - mshawa - 09-04-2024 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; Which of the cases violates Rule 10.6 while providing the rationale? RE: Further guidance on MISRA-C 2012 Rule 10.6 - misra-c - 08-08-2024 C18 para 6.5.3.4 defines that sizeof(x) generates an unsigned integer constant (long or long long?) and is therefore not within the scope of MISRA C Appendix D.7 By MISRA C Appendix D.6.1(2) an integer constant of unsigned type is the UTLR of the value (hence essentially unsigned char) Case 1: uint32_t = ( uint8_t + uint8_t ) + uint16_t ==> uint8_t + uint16_t /* Non-compliant - widened u16 -> u32 */ Case 2: uint32_t = uint32_t + uint32_t + uint16_t /* Compliant - all in u32 */ Case 3: uint32_t = uint8_t + ( uint8_t + uint16_t ) /* Non-compliant */ Case 4: uint32_t = uint8_t + uint16_t + uint8_t /* Non-compliant */ |