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

  • 'C' does not have a specific value for true - so it seems reasonable to disallow specific equality tests against true

    MISRA have a forum: www.misra.org.uk/.../index.php - that would be the place to ask...

  • Hello Eric,

    I would like to better understand your setup.

    I am assuming you are using MDK-ARM v 5.25; ARM Compiler 6 & you call PC-Lint from the Keil IDE to check your code.

    Some background questions:
    - Are you using this lint configuration file? C:\Keil_v5\UV4\Lint\co-ARMCC-6.lnt
    - Are you running Lint 9 or Lint 8?
    - What is the full lint error message you get?
    - Are you compiling for C99 standard?
    - What MISRA Standard are you checking against? 2012?
    - How are you defining "true" - is it a typedef? Could you provide a code snippet I could run through lint?

    - If you are getting message or error codes from Lint, these forum threads may be interesting to you

    - For 9034 or 9030 " href= "http://www.gimpel.com/Discussion.cfm?ThreadID=104">www.gimpel.com/Discussion.cfm
    - For 731: www.misra.org.uk/.../viewtopic.php

  • For the benefit of future readers, see also discussion at

    http://www.keil.com/forum/63386

  • 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.