07-11-2014, 09:17 AM
You are correct in saying that small unsigned types are promoted to a "signed int" standard type, but have an essentially unsigned type. This means that ~ on unsigned types is allowed by MISRA-C:2012, yet would produce different values depending on whether your implementation is one’s or two’s bit complement implementation.
This is only an issue if the resultant value is treated as a signed value, otherwise the bit pattern is consistent with what a user would expect. Any attempt to use the value of the result in an essentially signed context will produce a violation of rule 10.1, 10.3 or 10.4.
This is only an issue if the resultant value is treated as a signed value, otherwise the bit pattern is consistent with what a user would expect. Any attempt to use the value of the result in an essentially signed context will produce a violation of rule 10.1, 10.3 or 10.4.
Posted by and on behalf of the MISRA C Working Group