06-09-2010, 10:14 AM
The underlying type of (uint_8)s8a is uint_8.
The type of the constant 0x7F is int. The underlying type of 0x7F is therefore the smallest signed integer type that can hold it. This will be implementation-defined, but on many implementations it will be signed char.
There must therefore be an implicit conversion between signed and unsigned underlying types and this conversion violates rule 10.1.
To avoid this, you could write (uint_8)s8a & 0x7Fu because the 'u' suffixes forces 0x7F to take an unsigned type.
The type of the constant 0x7F is int. The underlying type of 0x7F is therefore the smallest signed integer type that can hold it. This will be implementation-defined, but on many implementations it will be signed char.
There must therefore be an implicit conversion between signed and unsigned underlying types and this conversion violates rule 10.1.
To avoid this, you could write (uint_8)s8a & 0x7Fu because the 'u' suffixes forces 0x7F to take an unsigned type.
Posted by and on behalf of the MISRA C Working Group