Learn MISRA-C-CPP with Real Code Examples

Updated Nov 27, 2025

Explain

MISRA provides a set of guidelines to avoid unsafe or undefined behavior in C/C++.

Focuses on safety, portability, readability, and maintainability of code.

Widely used in safety-critical embedded software development.

Rules cover language usage, coding practices, and static analysis requirements.

Adopted by automotive, aerospace, defense, and industrial sectors.

Core Features

MISRA C: 2004 / 2012 standard rules

MISRA C++: 2008 standard rules

Static analysis-friendly coding practices

Defined subsets to reduce undefined behaviors

Guidelines for portability across compilers and platforms

Basic Concepts Overview

Rule - a single guideline for safe coding

Directive - a high-level recommendation

Mandatory Rule - must always be followed

Advisory Rule - recommended best practice

Deviation - documented justification for violating a rule

Project Structure

Source files (.c/.cpp)

Header files (.h/.hpp)

Configuration files for analysis tools

Documentation of deviations

Test code for verification

Building Workflow

Write C/C++ code following MISRA guidelines

Run static analysis for rule violations

Document any justified deviations

Refactor code to address violations

Maintain compliance throughout project lifecycle

Difficulty Use Cases

Beginner: simple embedded C code adherence

Intermediate: C++ projects with OOP and templates

Advanced: multi-module ECU software

Expert: automotive or aerospace safety-critical projects

Architect: large-scale embedded system compliance

Comparisons

MISRA C vs CERT C: MISRA focuses on embedded safety, CERT on security

MISRA C++ vs C++ Core Guidelines: MISRA is strict for critical systems, Core Guidelines are general-purpose

MISRA C vs AUTOSAR C: MISRA is language rules, AUTOSAR provides architecture & middleware guidance

MISRA C vs JSF++: Both target safety, MISRA more industry-wide

MISRA vs ISO C/C++ standards: MISRA adds safety-focused constraints to standard C/C++

Versioning Timeline

1998 - MISRA C first edition released

2004 - MISRA C updated edition

2012 - MISRA C:2012 published

2008 - MISRA C++:2008 released

2016 - MISRA C:2012 Amendment 1

2020 - MISRA C:2012 Amendment 2

2022 - MISRA C++:2012 review discussions

Glossary

MISRA - Motor Industry Software Reliability Association

Rule - specific coding requirement

Directive - high-level recommendation

Deviation - approved rule violation

Static Analysis - automated code checking