What you’ll learn:
- Why MISRA C/C++ is used for automotive applications.
- Why MISRA C/C++ is good for any application.
- How can MISRA C/C++ be tuned for your application development process.
This video is the third in a series about MISRA C and MISRA C++ from the MISRA Consortium. These programming guidelines are designed to improve software quality by identifying and restricting functionality within the languages. MISRA C came about in the late 1990s and was targeted at the automotive space, where software was needed to meet the various Automotive Safety Integrity Levels (ASIL) used in software development for cars.
I talked with Andrew Banks, Technical Specialist at TASKING/LDRA, about why these standards are useful in non-automotive applications (watch the video above). We discuss why MISRA C/C++ should be used for any application.
Tailoring MISRA C/C++ for Embedded Applications
The guidelines focus on avoiding possible compiler differences, preventing the use of error-prone constructs, limiting complexity, and providing a set of best practices. The latter includes maintainability support using consistent naming conventions and commenting syntax.
>>Check out this TechXchange for similar articles and videos
Many embedded applications are similar to automotive applications in that things like static memory allocation are preferred over dynamic memory allocation. Still, many embedded applications are easier to write or may require dynamic memory allocation. The rules employed by static-analysis tools can be adjusted to accommodate these preferences while checking for other rules that will help to develop safe and secure code.
The biggest challenge for embedded developers using MISRA C/C++ is to determine what mix of rules will work best for their development and design process. MISRA-C:2012 has 143 rules and 16 directives. MISRA C++:2008 included 228 coding rules.
Rules are classified as advisory, required, and mandatory. The mandatory part is more about certification that’s not necessarily needed for many embedded applications. It’s still a good idea to minimize weakening or excluding a rule.
A new version of MISRA C and MISRA C++ was published in 2023.
Using static-analysis tools is easiest when starting with a new code base. Applying it to an existing code base must usually be done in an incremental fashion, as the code likely won’t follow all of the rules. Likewise, changing the code to meet the rules can be challenging and potentially error-prone as well.