17-06-2016, 01:11 PM
The following question has been submitted to the working group.
Please can you explain which of the following are non-compliant with rule 10.3.
Exception 1 says that
Please can you explain which of the following are non-compliant with rule 10.3.
Code:
typedef signed char sint8_t;
typedef unsigned char uint8_t;
sint8_t s8;
uint8_t u8;
s8 = 6L; /* not compliant - STLR is essentially signed long */
u8 = 6UL; /* not compliant - as above */
u8 = 6; /* compliant by exception 1 */
u8 = 6L; /* compliant or not ? */
Quote:a non-negative integer constant expression of essentially signed type may be assigned to an object of essentially unsigned type if its value can be represented in that typeThe value of 6L can be represented in an unsigned char type and so this implies that the above assignment is compliant by exception 1. However this is not consistent with u8 = 6UL being non-compliant.
Posted by and on behalf of the MISRA C Working Group