3 ms·
I'm sorry, but you've clearly just skimmed this and haven't worked with, nor understood, the purpose of MISRA C. For starters, unless it's changed substantially
by smcl 3y ago
I'm sorry, but you've clearly just skimmed this and haven't worked with, nor understood, the purpose of MISRA C. For starters, unless it's changed substantially since I worked with it, MISRA C forbids use of functions like malloc which rules it out for an enormous number of applications. Plus it's a little bit fuzzy in how some of the rules should be interpreted. Like there was one where it says there shouldn't be commented-out fragments of code (our response was to try to parse the lines of each comment, if they succeeded raise a MISRA-specific compile error). There were a few more weird things with MISRA C, but these were a couple that stuck with me.
It's not a "sane" subset of C you can just pick up and run with. It's a narrow subset of C for a very specific use case.
- cbsks 3y agoEvery place that I’ve worked chooses a subset of MISRA rules to follow and ignores the rest. A rationale for the ignored rules is written in a document somewhere which can be provided to safety auditors. A deviation for a rule in the “required” set can be made for specific cases. The “no commented-out fragments of code” is a weird one. It was not required at my previous employer, but it is at my current. It means that you can’t have comments like this without a deviation: // This function is only called from // main() Which is much more readable to me than: // This function is only called from // main I see what they are trying to prevent, which is people commenting out code instead of removing it. In my experience, code that is commented out usually means that it was committed accidentally, or the author didn’t really understand what the old code was doing so they didn’t delete it entirely.
- eternityforest 3y agoMISRA is pretty narrow, but I think the comment still stands because almost all the stuff I'd actually enjoy doing in C, can probably be done with MISRA. If it needs malloc, it might be something that could be C++ or Rust
- pjmlp 3y agoThat would be AUTOSAR, which is now being integrated into MISRA as well. https://www.autosar.org/news-events/detail?tx_news_pi1%5Baction%5D=detail&tx_news_pi1%5Bcontroller%5D=News&tx_news_pi1%5Bnews%5D=39&cHash=e4f521f7b674bdfd7c1fade308cf2ea8 https://www.autosar.org/news-events/detail?tx_news_pi1%5Bact...
- nullc 3y agoMISRA doesn't really "forbid" anything. If you have a variation of the MISRA rules you're supposed to document and justify it. > like malloc which rules it out for an enormous number of applications. Malloc is overrated. If your program can't fail you need to have memory for its peak usage. If you do, you can obtain the memory up front and use it.