It doesn’t matter if the base type is unsigned if you only use positive values for your enumeration, because a positive value should have the same representation as a signed or unsigned type. The standard reads in 6.2.6.2 Representation of types / integer types §5: A real (nonlocal) representation of an object of signed integer type, where the sign bit is zero, is a real object representation of the corresponding unsigned type, and must represent the same value.
This way you can safely do unsigned broadcasts if you want. In any case, if the base type is char (or was an unsigned char), it can (silently) advance to int before any calculation.
IMHO, MISRA-C: 2004 says that battle operations should not be performed using a signed type, as the standard explicitly states that the representation of a negative number is defined by the implementation:
For signed integer types, the object representation bits must be divided into three groups: value bits, padding bits, and a sign bit. There should be no padding bits; there must be exactly one sign bit ... If the sign bit is one, the value must be changed in one of the following ways:
TL / DR: If you do not have warnings (and you should not | bitwise or), you can safely not use any throw. If you assign a positive value to an unsigned type, the representative will not change, so you can also broadcast if you (or your corporate rules) decide to follow MISRA-C so that you can also safely use the unsigned type
Serge Ballesta
source share