08-08-2024, 03:29 PM
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 */
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 */
Posted by and on behalf of the MISRA C Working Group