Episode 152: MISRA with Johan Bezem

Filed in Episodes by on December 28, 2009 2 Comments

Recording Venue:
Guest(s): Johan Bezem

Host(s): Michael
Our guest Johan Bezem explains the idea behind and the benefits of MISRA. MISRA defines guidelines for C and C++ programming in order to ensure quality. While it got started for embedded automotive development, it is more generally applicable.

Links:

Tags: , ,

Comments (2)

Trackback URL | Comments RSS Feed

  1. jbezem says:

    “if you ever feel you need it” that’s about the right condition. Isn’t that the case for many features of C (and many other languages)?
    Consider a different example I just encountered a few days ago:
    On refactoring a parallel driver I wanted to replace a set of define-constants (typeless in C) with a set of constant variables. Since these variables were used in multiple files, I put external declarations in a header file. In my module, everything was fine, but in other modules the variables were also used as the dimension of certain arrays. And to do that (still using C90, not 99), the compiler needed to know the actual value of the constants in those modules too.
    The only other solution that worked for my current compiler was to use “static const” variables defined (not just declared!) in a header file. So basically every compilation unit thus go its own copy of the constant variables, which were then optimized-away by the compiler again.
    Now, if you know a little C you know this is ugly, if not criminal. You never define variables in a header file, just declare them. But “if you feel you need it”, I think it’s good to know your possibilities.

    FWIW,

    Johan

    PS: After a code review we reverted back to using defined constants (macros), but that’s a different issue. Both solutions are in violation of our coding guidelines, so there’s no ‘good’ way to solve this.

    Johan Bezem
    http://www.bezem.de/

  2. Leibnix says:

    The problem with weird code like the switch statement in this episode is that even though we are told it’s BAD, once you have seen the pattern it it’s going to be very hard to resist the temptation to use it if you ever feel you need it.

Leave a Reply

Your email address will not be published. Required fields are marked *


*