If you read rule 12.6 it says "check Boolean Expressions" in the appendix. There we can read
"Boolean-by-enforcement values can be introduced by implementing a specific type enforcement mechanism using a tool. A Boolean type could be associated with a specific typedef, and would
then be used for any objects that are Boolean. This could bring many
benefts, especially if the checking tool can support it, and in
particular it could help avoid confusion between logical operations
and integer operations."
MISRA-C:2004 assumes C90, and in C90 there is no bool type, you have to typedef it yourself, like you have done. Since your intention is to have a type which is effectively boolean, the code is just fine. In fact, your code follows MISRA recommendations beyond the mandatory ones.
The problem lies with your tool: it either does not support to allow a specific boolean type as per MISRA recommendations, or it is misconfigured.
B
andb
intentional? (C language is case sensitive). Does your static analysis tool know that your MISRA boolean type isboolean
? (It might not be able to figure it out by itself, you might have to tell it). This just should be OK by MISRA (assuming it was supposed to beA = !B
). Ternary operators in the answers also should not be necessary as for example avar == 0
expression gives a boolean result, which can be assigned to a boolean variable right away without any voodoo magic. – Illative