18-10-2018, 01:25 PM
The result of the cast "(int8_t)256U" is implementation-defined since 256 can not be represented by a signed 8-bit type. A tool supporting directive 1.1 may generate a warning in order to direct the user to document the behaviour of such a cast.
We would recommend removing the "U" rather than adding a cast.
An alternative would be to use a mask so that the value always fits the int8_t range.
We would recommend removing the "U" rather than adding a cast.
Code:
int8_t s8a = 256; // implicit narrowing conversion violates rule 10.3
Code:
int8_t s8a = (int8_t)(256U & 0xffU);
Posted by and on behalf of the MISRA C Working Group