Code: Select all
uint8_t b = '\r';//Non-compliant, explicitly unsigned
Code: Select all
uint8_t b = static_cast<uint8_t>('\r');//Compliant
Moderators: david ward, misra cpp
Code: Select all
uint8_t b = '\r';//Non-compliant, explicitly unsigned
Code: Select all
uint8_t b = static_cast<uint8_t>('\r');//Compliant
Code: Select all
uint8_t str[] = {
static_cast<uint8_t>('m'),
static_cast<uint8_t>('i'),
static_cast<uint8_t>('s'),
static_cast<uint8_t>('r'),
static_cast<uint8_t>('a')
};
Don't rely on the signedness of plain char. Period.
Code: Select all
extern char x; if (x == -1)//non-compliant as it is implementation defined whether char is signed or unsigned