Guide · Coding rules

MISRA C and MISRA C++: the coding rules of critical software

MISRA C and MISRA C++ define a safe subset of the C and C++ languages. Their rules rule out ambiguous, non-portable or error-prone constructs. Born in the automotive industry, they have become the reference for safety-critical embedded software, from avionics to medical devices. Here is what they contain, which edition to choose, what "MISRA compliant" means, and how to apply them to code that already exists.

Definition

What is MISRA?

MISRA (Motor Industry Software Reliability Association) is a consortium born in the British automotive industry in the 1990s. It has published coding rules for C since 1998, and for C++ since 2008.

C and C++ leave a lot of freedom: undefined behavior, implicit conversions, unspecified order of evaluation, constructs whose result depends on the compiler. MISRA rules close these doors. The code becomes more predictable, more portable from one compiler to another, and easier to review and verify.

Today, MISRA reaches far beyond the automotive industry: aerospace, railway, medical, industrial automation, defense, energy.

Editions

The editions

EditionTarget languageIn short
MISRA C:1998C90First edition, 127 rules.
MISRA C:2004C90142 rules, grouped by topic.
MISRA C:2012C90 and C99143 rules and 16 directives, in three categories: mandatory, required, advisory. A 2016 amendment adds security rules.
MISRA C:2023up to C11 and C17Brings together MISRA C:2012 and its amendments. Supports C11 and C17, including multithreading and atomic types.
MISRA C:2025C90 to C18Current edition, more than 200 rules and directives. Guidance for automatically generated code is published separately.
MISRA C++:2008C++03First edition for C++.
AUTOSAR C++14C++14Rules published by the AUTOSAR consortium in 2018 for modern C++, based on MISRA C++:2008.
MISRA C++:2023C++17Current edition, 179 rules and directives. Replaces MISRA C++:2008 and incorporates much of AUTOSAR C++14.

New project

Take the most recent edition that covers your language version: MISRA C:2025 for C, MISRA C++:2023 for C++17.

Ongoing project

It usually keeps the edition chosen at the start: switching editions midway means switching frameworks.

External requirement

Your customer or your standard may also impose an edition.

Organization

How the rules are organized

Rules and directives. A rule applies to the source code and is checked on the code. A directive also depends on documentation, requirements or process: a tool can only check part of it.

Three categories.

CategoryWhat it requires
MandatoryAlways followed. No deviation allowed.
RequiredFollowed, unless there is a formal, justified and approved deviation.
AdvisoryFollowed as far as possible. A departure needs no formal deviation, but it must be documented.

Decidable or not. A rule is decidable when a tool can always tell whether the code complies with it. Other rules depend on the values taken at run time. For those, a tool may miss a violation or wrongly report one, and a review is still needed.

File by file, or whole program. Some rules can be checked on a single source file. Others require analyzing the program as a whole.

Content

What the rules require

Every MISRA rule comes with a rationale; none is a matter of personal taste. A few typical topics in C:

Types and conversions

An "essential type" model governs implicit conversions, mixing signed and unsigned integers, and loss of precision.

Values

No variable is read before it has been initialized, and no undefined behavior is allowed.

Memory

The dynamic memory allocation functions of the standard library are ruled out, and the use of pointers is restricted.

Control flow

No recursion, goto discouraged, well-formed switch statements.

Expressions

No ambiguous side effects; the order of evaluation must be explicit.

Preprocessor and library

Macros are restricted, and some standard library functions are ruled out.

MISRA C++ follows the same spirit, with rules specific to C++: conversions, resource management, inheritance, exceptions, templates.

Compliance

What does "MISRA compliant" mean?

There is no MISRA certification. The development team claims compliance itself, project by project. The framework is set by the MISRA Compliance:2020 document, common to C and C++, which rests on four elements.

The enforcement plan

Guideline Enforcement Plan: for each rule, how it is checked, by a tool, by a review, or both.

The re-categorization plan

Guideline Re-categorization Plan: the project's own categories. A rule can be made stricter, never more lenient. Only an advisory rule can be disapplied.

Deviations

Every departure from a required rule is justified, assessed and approved.

The compliance summary

Guideline Compliance Summary: for each rule, its status, that is compliant, compliant with deviations, or disapplied.

A project can claim compliance when two conditions are met: all mandatory rules are followed, and all required rules are followed or covered by a formal deviation.

A tool does not make code compliant. It may not cover every rule. It cannot always decide on undecidable rules, and it only checks part of the directives. Compliance is the outcome of a process; static analysis is one link in it.

Standards

MISRA in the safety standards

StandardWhat it asks for
ISO 26262-6 (automotive)Modeling and coding guidelines; MISRA C is cited as an example.
IEC 61508-3 (industrial)Highly recommends a coding standard, at all SIL levels.
EN 50716 (railway)Makes coding standards mandatory at SIL 3 and SIL 4.
DO-178C (avionics)Software code standards defined by the applicant, and verification that they are followed. MISRA is often their basis.
IEC 62304 (medical)For classes B and C, software unit acceptance criteria, for example compliance with a coding standard.

None of these standards mandates MISRA as such: they ask for a coding standard, and MISRA is the most common choice for C and C++.

Method

Applying MISRA to existing code

  1. Choose the edition and write the enforcement plan.
  2. Take a first inventory: the number of violations per rule and per category. Read it rule by rule, not as a whole.
  3. Deal with mandatory rules first, then required rules.
  4. Set a rule for new code: no new violations.
  5. Justify the departures that must remain with reviewed and approved deviations.
  6. Track the trend, module by module, up to the audit.
TiCS

Tracking MISRA across all your projects with TiCS

TiCS does not check MISRA instead of your tools: it takes in the results of your rule checkers and your C and C++ analyzers, for example PC-Lint or Parasoft C++test. It then tracks them over time:

  • the TQI: coding rule violations are part of this indicator, along with the other quality criteria;
  • quality gates: they stop new code from adding violations;
  • deviations: they are requested and justified, approved by a second person and traced, ready to be shown in an audit;
  • trends: they show whether the number of violations is going down, project by project and across the whole portfolio.

Languages and tools supported by TiCS →
Guide: static code analysis →

Deviations, ready for the audit1 min 35 s · silent animation

Key takeaways

  • MISRA C and MISRA C++ define a safe subset of C and C++, the reference for safety-critical embedded software.
  • The current editions are MISRA C:2025 and MISRA C++:2023, for C++17.
  • Rules are mandatory, required or advisory; only required rules allow a formal deviation.
  • MISRA compliance is claimed, not certified: enforcement plan, justified deviations, rule-by-rule summary.
  • On existing code: an inventory, mandatory rules first, no new violations in new code.
FAQ

Frequently asked questions

Is MISRA mandatory?

Not as such. Safety standards require a coding standard, and MISRA is the most common choice for C and C++. A customer may also impose it by contract.

MISRA C:2012, 2023 or 2025?

For a new project, MISRA C:2025. MISRA C:2023 brings together MISRA C:2012 and its amendments. A project started on an earlier edition usually keeps it until the end.

AUTOSAR C++14 or MISRA C++:2023?

MISRA C++:2023 targets C++17 and incorporates much of AUTOSAR C++14. For a new C++ project, it is the reference.

MISRA or CERT C?

CERT C focuses first on security; MISRA C focuses on safety and includes security rules. The two overlap widely, and the same tool can often check both.

Is a "MISRA-compatible" tool enough?

No. Check which rules it actually covers. Plan a review for undecidable rules and for directives. Finally, keep the enforcement plan, the deviations and the compliance summary up to date.

Where can I get the MISRA documents?

From the MISRA website, which sells its documents in PDF format, including MISRA Compliance:2020.

Track your MISRA rules across all your code

A free TiCS proof of concept, installed and configured by a Precilog consultant, with your own rule checkers.

Request a proof of concept →

Static code analysis  ·  TiCS  ·  Languages and integrations  ·  Standards  ·  ISO 26262  ·  Learn