This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

MISRA inconsistency

evidently MIrA does not allow if (bool_something == true)
but doee not allow
if (int_comething)

am I confoosed between the various versions, trying to use 2012

Parents
  • if (bool_something == true)
    but doee not allow
    if (int_comething)

    And they're not entirely wrong about that. A boolean is already either true or false (and yes, there is an actual definition for that right there in the language --- been so for 18+ years now). Comparing it to true or false is therefore just superfluous, and faintly suggests that the author of such code doesn't know about the difference boolean and integer expressions. Getting a MISRA warning and having to think about how to resolve it is actually a useful lesson in this case.

    For the integer side of this, I don't fully agree with MISRA. "if (integer)" has been a bog-standard C idiom since long before either MISRA or even the ISO/C standard existed. People who don't understand that idiom on sight really have no business writing code in the application fields MISRA is intended for; and MISRA alone can't teach away that lack, either.

Reply
  • if (bool_something == true)
    but doee not allow
    if (int_comething)

    And they're not entirely wrong about that. A boolean is already either true or false (and yes, there is an actual definition for that right there in the language --- been so for 18+ years now). Comparing it to true or false is therefore just superfluous, and faintly suggests that the author of such code doesn't know about the difference boolean and integer expressions. Getting a MISRA warning and having to think about how to resolve it is actually a useful lesson in this case.

    For the integer side of this, I don't fully agree with MISRA. "if (integer)" has been a bog-standard C idiom since long before either MISRA or even the ISO/C standard existed. People who don't understand that idiom on sight really have no business writing code in the application fields MISRA is intended for; and MISRA alone can't teach away that lack, either.

Children
No data