MISRA-C doesn't allow implicit checks against zero - all inputs to conditional statements must be "essentially boolean", which is what you get if you explicitly use logical operators like ==
.
In addition, MISRA-C has various rules blocking you from mixing "essenitally signed" and "essentially unsigned" in the same expression, and thereby relying on implicit type promotions. So you can't write if (fn1() == 1)
for that reason, since 1
is a signed type and there's also a rule requiring all integer constants to have u
suffix.
So one possible fix is if (fn1() == 1u)
. However, since the function only returns 0 or 1, you can also cast its result to boolean type and that would be fine too: if ((bool)fn())
. The best solution is however to rewrite the function to return bool
, after which you can use if(fn1())
.