Every embedded team that adopts MISRA C seems to go through the same week. Someone switches on the MISRA checker in the static analyser, runs it over a codebase that has grown for years, and the report counts its findings in the thousands. A spreadsheet appears. Someone suggests suppressing the advisory rules. Someone else asks whether the customer will even look.
That week is avoidable. Most of the pain comes from treating MISRA C as a list of rules to satisfy at the end, when the MISRA documents themselves describe something different: a disciplined process, agreed with your customer at the start, with a defined way to handle the cases where a rule does not fit. The document that defines what “MISRA compliant” means, MISRA Compliance:2020, is free, about 30 pages long, and far less read than it deserves.
This post is the practical version. It explains what a compliance claim actually consists of, which flexibility the framework gives you and which it does not, and a step-by-step strategy that works for new code and for the legacy code you cannot rewrite. It also connects to my Automotive SPICE guide: the assessment model names MISRA rule sets as an example of unit verification in SWE.4.
A note on sources. The compliance rules below come from MISRA Compliance:2020, published by MISRA and mandatory for the current MISRA C editions. I paraphrase it rather than quote it; for the guidelines themselves you need your own licensed copy of MISRA C. The strategy sections at the end are my own recommendations, and I label them as such.
Which “MISRA C:2012”?
The title of this post uses the name most contracts and job descriptions still use. Strictly speaking, MISRA C:2012 was the third edition of the guidelines, and everything since has been a revision of it:
- MISRA C:2012 (third edition, 2013) added support for C99, introduced directives next to rules, and the Mandatory category.
- Amendment 1 (2016) added security guidelines. A first revision followed in 2019.
- Amendments 2, 3 and 4 (2020 to 2023) covered C11 and C18, ending with multi-threading and atomics.
- MISRA C:2023 consolidated the base document, amendments and corrigenda into one book.
- MISRA C:2025, published in March 2025, is the current version according to MISRA itself, an incremental update with a few new rules and a handful of removed or reorganised ones.

What does that mean for you? When a contract says “MISRA C:2012”, ask which revision and which amendments it means, and write the answer down. Your static analyser needs the same answer. The good news is that the compliance framework is the same for all of them: since 2020, MISRA has made MISRA Compliance:2020 the rulebook for what a compliance claim must contain. Everything below applies whichever edition you are held to.
What “MISRA compliant” actually means
The first surprise for most teams: MISRA compliance does not mean zero warnings. It means you can show, for one project, that:
- the code was developed under a disciplined process;
- everyone knows exactly which guidelines apply, and how strictly;
- each guideline was checked by a method that works;
- every violation of a required guideline is covered by an approved deviation;
- code from outside the project has a known status.
Those five points are paraphrased from the introduction of MISRA Compliance:2020. Two details matter immediately. Compliance can only be claimed for a project, not for an organisation. And the acceptance criteria are a matter for negotiation between the customer (the acquirer) and the supplier, ideally at the start of the project, not the end.
In practice, the claim is carried by four documents:

- The guideline re-categorization plan (GRP) says which guidelines apply and with which force. It is agreed with the customer at the outset.
- The guideline enforcement plan (GEP) lists every guideline and how it is checked: which tool and message, which compiler warning, or which manual review procedure. It is backed by the tool versions, configuration files and options, and evidence that the tools actually detect what you claim.
- Deviation records document every approved violation of a required guideline, optionally based on pre-agreed deviation permits.
- The guideline compliance summary (GCS) is produced at the end and records, for every guideline, the level of compliance you claim.
None of these is exotic. Modern static analysers can generate most of the GEP and GCS for you. The hard part is the decisions behind them, which is what the rest of this post is about.
Categories, and the one lever you control
Every MISRA C guideline has a category, and the category decides what a violation costs you:
- Mandatory: a violation is never permitted. No deviation can cover it.
- Required: a violation is allowed only when covered by a formal deviation.
- Advisory: recommended as far as reasonably practical. Violations must be identified, but do not need a deviation.
The GRP is your lever. At the start of the project, you and your customer may move guidelines to a stricter category, and you may switch advisory guidelines off completely with a fourth category, Disapplied, as long as the reason is written down. What you may never do is make a guideline weaker: a mandatory guideline cannot be re-categorized at all, and a required guideline cannot become advisory or disapplied.

That asymmetry is deliberate, and it is useful. MISRA observes that compelling reasons to deviate from most required guidelines are rare, so many of them can safely be promoted to mandatory. That stops deviations multiplying for rules that never needed them, and it makes the remaining deviations stand out.
Here is what a realistic GRP fragment could look like for a fictional body-controller project:
| Guideline | MISRA category | Revised category | Why |
|---|---|---|---|
| Rule 2.1 (no unreachable code) | Required | Mandatory | We have never needed an exception |
| Rule 10.6 (composite expression to wider type) | Required | Required | Known compiler code-generation issue; covered by a deviation permit |
| Dir 4.6 (sized typedefs instead of basic types) | Advisory | Required | Our integer sizes differ between two targets |
| Rule 8.13 (pointer to const where possible) | Advisory | Required | Cheap to follow, catches real mistakes |
| Rule 2.7 (no unused parameters) | Advisory | Advisory | Callback signatures are fixed by the framework |
| Rule 15.5 (single point of exit) | Advisory | Disapplied | Early returns are clearer in our error handling; MISRA C:2025 disapplies it by default |
The last column is the part people skip, and the part a customer reads first. A GRP without reasons looks like a list of rules someone found inconvenient.
Why your tool cannot simply say yes or no
The second source of pain is expecting the static analyser to be an oracle. MISRA C gives every guideline properties that tell you how far a tool can go, and reading them before planning the enforcement saves a lot of frustration.
Rules and directives. A rule is defined entirely by the source code, so a tool can in principle check it. A directive also refers to design documents, processes or requirements, so tools can only help and different tools may judge it differently. For a compliance claim, both count the same.
Analysis scope. Some rules can be checked one file at a time (a single translation unit). Others, such as “each external identifier has exactly one definition”, only make sense across the whole program (system scope). Two files that are each fine on their own can be in violation once linked together.
Decidability. For a decidable rule, a correctly configured tool can always answer yes or no. For an undecidable rule, the honest answer is sometimes “possibly”, because it depends on run-time values or on whether a path is ever taken.

Undecidable findings are not exotic. Most of them come from a handful of patterns that every embedded codebase contains. Here are five I see constantly, each with the tool’s dilemma and the fix that removes it.
1. A variable that may never be set.
extern void read_sensor(uint16_t *out);
uint16_t sample(void)
{
uint16_t raw; /* not initialised here */
read_sensor(&raw); /* may or may not write to raw */
return raw; /* is raw set? depends on read_sensor() */
}
The tool cannot know whether raw is set without looking inside read_sensor(), which may live in another file or in a library without source. Fix: initialise raw, or let read_sensor() return a status that the caller checks.
2. An array index that comes from outside.
static const uint8_t gain_table[8] = { /* ... */ };
uint8_t get_gain(uint8_t mode) /* mode arrives in a CAN message */
{
return gain_table[mode]; /* only safe if mode < 8 */
}
Whether this reads outside the array depends on a value only known at run time. Fix: check the range where the value enters, and decide explicitly what happens when it is wrong. MISRA’s Directive 4.14, which asks for values from external sources to be validated, points the same way.
uint8_t get_gain(uint8_t mode)
{
return (mode < 8u) ? gain_table[mode] : DEFAULT_GAIN;
}
3. A shift by a variable amount.
uint32_t channel_mask(uint8_t channel)
{
return 1u << channel; /* undefined behaviour if channel >= 32 */
}
The shift is fine for channels 0 to 31 and undefined for anything else. Fix: guard the range, or replace the shift with a lookup table when the set of channels is small and fixed.
4. A division by something that might be zero.
uint16_t average(uint32_t sum, uint16_t count)
{
return (uint16_t)(sum / count); /* count == 0 after a reset? */
}
Division by zero is undefined behaviour, which MISRA C forbids in general (Rule 1.3), but whether count can be zero is a run-time question. Fix: handle count == 0 explicitly, and make the result for that case a design decision rather than an accident.
5. A resource that is not released on every path.
if (bus_lock(&spi) != OK) { return ERR_BUSY; }
if (bus_read(&spi, buf, len) != OK) { return ERR_READ; } /* lock never released */
bus_unlock(&spi);
The tool has to follow every path to see that one of them leaves the bus locked. Fix: give the function one cleanup path that always runs. Interestingly, this is the case where the old “single point of exit” style helps, even though MISRA C:2025 no longer requires it by default.
The common thread: in each case the property depends on a run-time value or on which path is taken, so a tool can only say possibly. And in each case the fix is the same idea MISRA Compliance recommends for undecidable rules: make the property visible in the code, with explicit initialisation, range checks at the boundary and a single cleanup path. Code that a tool can reason about is also code a reviewer can reason about.
The consequence for planning: decidable single-file rules belong in the fast checks developers run all the time; system rules need a full-build analysis, typically nightly or per merge; undecidable findings need a documented review step; and directives need an owner and a procedure, not a tool switch.
The strategy, step by step
With the framework in place, a realistic strategy has six steps. Five of them are what MISRA Compliance asks for anyway, put in a practical order. One, the baseline, is my own recommendation for codebases that already exist.

1. Agree before you code. MISRA Compliance is explicit that the decision to apply MISRA should be taken at the outset, and that the GRP is agreed between customer and supplier at the start. Use that meeting to fix the edition (see above), the GRP, and a first set of deviation permits for the cases you already know you will need, such as register access through compiler extensions. A deviation agreed in week one costs a paragraph; the same deviation argued about in the final delivery review costs a week.
2. Configure and validate the tools. A MISRA checker is only as good as its configuration. It must know the language version you compile with, the sizes of your integer types, and the compiler extensions you use; otherwise it will both miss real violations and invent false ones. It must be able to analyse the whole program, not just single files, or system-scope rules go unchecked. And you should show that it works: MISRA suggests a set of small test files, each violating one guideline, which the tool must flag. All of this goes into the GEP.
3. Split native and adopted code. Code your project writes (native code) and code it takes from elsewhere (adopted code) are treated differently. More on that in the next section.
4. Freeze a baseline, gate new code. Also in the next section; this is where existing projects win or lose.
5. Check as you write. MISRA Compliance requires compliance to be checked as code is developed, before it goes to review or unit testing, and warns that checking late leads to re-coding, re-reviewing and re-testing, with new defects slipping in along the way. In practice: decidable single-file rules run in the editor or pre-commit hook, the full system analysis runs in CI on every merge request, and a merge request with new unresolved findings does not get merged.
6. Triage, deviate, report. Every finding is either fixed, investigated, or covered by a deviation, and the GCS at delivery summarises the result. The section after next shows how to keep that from becoming bureaucracy.
Legacy and adopted code: the ratchet
Almost no automotive project starts from an empty repository. MISRA Compliance calls everything that comes from outside the project adopted code, and its list will look familiar: the standard library, device drivers from the semiconductor vendor, middleware such as an RTOS or protocol stack, third-party libraries, code generated by modelling tools, and legacy code from earlier projects.

The framework asks two separate questions about adopted code: was it developed to an adequate level of safety and security, and was it developed to comply with MISRA? It points out that MISRA compliance is neither necessary nor sufficient for the first. In practice, three rules follow:
- Adopted code gets its own GRP, usually less strict than the native one. That does not lower the bar; it means more violations will need review and justification instead of fixes. One exception never moves: code that violates a guideline MISRA itself categorises as mandatory can never be called compliant.
- Every violation in adopted source code is reviewed, and covered by a deviation where required. MISRA lists “non-compliant adopted code” as a legitimate reason for a deviation, provided you show the violation does not compromise safety or security.
- The standard library is not required to comply, but your calls to it are still checked, for example for argument types.
Now the legacy part. MISRA Compliance itself recognises that refactoring proven code just to satisfy the guidelines can introduce more risk than it removes, and leaves that judgement to the project. My practice turns that judgement into a mechanism I call the ratchet:
- Run the full analysis on the existing code once and record the result as a baseline.
- Triage the baseline once: fix every violation of a mandatory guideline and anything that is a real defect; cover the rest with reviewed deviations under the legacy GRP.
- Gate new and changed code: a merge request may not add findings. New files must be clean; changed functions must not get worse.
- Clean legacy findings opportunistically when a file is touched anyway, and the change is covered by its tests.
- Report the trend, not just the total.

The ratchet turns an impossible one-off clean-up into a slope that only goes one way. Most static analysers support it directly, through baselines, “new findings only” quality gates or differential analysis between branches. What matters is that the baseline is reviewed and justified once, so it is evidence, not a hiding place.
Triage and deviations without the bureaucracy
A finding in your analysis report is not automatically a violation. MISRA Compliance sorts every message from the compiler or analyser into four categories, and each one has a different answer:

The preferred answer to a real violation is always the same: change the code. Only when that is undesirable or impossible does a deviation come into play, and MISRA is blunt about when it must not: not for the developer’s convenience, not when a reasonable alternative way of writing the code exists, not without considering how the violation affects other guidelines, not without a process, and not without the consent of a designated technical authority.
When a deviation is justified, it must rest on one of four reasons:
- Code quality: following the guideline would harm another quality characteristic, such as timing, maintainability or fault tolerance, while safety and security are preserved.
- Access to hardware: compiler extensions or low-level constructs that standard C cannot express. Encapsulate them in as few places as possible.
- Adopted code integration: violations that only appear when separately compliant components are combined.
- Non-compliant adopted code: code that was never written for MISRA, where you show the violation does not compromise safety or security.
A deviation record then captures five things: the guideline, the circumstances in which the violation is acceptable, the reason, the background, and the precautions and risk assessment. It also says where it applies: one location, or a register of all locations that share the same use case. MISRA’s own worked example is instructive: a project deviates from a type-conversion rule because the compiler generates a slow library call for the compliant form and a single multiply instruction for the non-compliant one, with measured timing impact and the alternatives that were rejected.
To keep this from becoming paperwork, use deviation permits: pre-approved use cases, agreed with the customer early, that a deviation record can simply refer to. MISRA publishes public permits for common cases, and you can add your own. In the code, a short, consistent tag that your tool understands links each location to its record:
/* Deviation DEV-012 (permit PRM-HW-03): register access via compiler
* extension, encapsulated in this module only. Reviewed: 2026-11-10. */
#define WDT_CTRL (*(volatile uint32_t *)0x40003000u)
The exact tag syntax depends on your analyser. What matters is that every suppression in the code points to a record, and every record lists its locations. A suppression without a record is not a deviation; it is a hidden violation.
Traps I see again and again
- Suppressions without records. An analyser comment that silences a warning is not a deviation unless it points to an approved record. Auditors search for suppression comments first.
- Treating advisory as optional noise. Advisory violations do not need deviations, but they must still be identified. If you really want to ignore an advisory guideline, disapply it in the GRP, with a reason.
- Trying to weaken required guidelines. The GRP cannot make a required guideline advisory or disapplied. If you need to deviate from one often, write a deviation permit for that use case instead.
- An analyser that does not match the compiler. Wrong integer sizes, an unknown compiler extension or the wrong language version produce false alarms and, worse, silent misses. Configure it from the same build settings the compiler uses.
- File-by-file analysis only. Fast, convenient, and blind to every system-scope rule. Run whole-program analysis at least on every merge.
- Leaving it to the end. MISRA’s own wording on this is unusually direct: compliance is not a tick-box exercise for the delivery phase.
- Violations that come from someone else’s header. A macro can be perfectly compliant on its own and still create a violation in your file when it is expanded:
/* vendor_api.h (adopted code) */
#define IS_VALID(p) ((p) != 0)
/* app.c (native code) */
if (IS_VALID(buf)) { ... } /* expands to (buf) != 0: a pointer compared
with the integer 0, reported in app.c */
MISRA Compliance uses a very similar example. The violation shows up in native code but belongs to the adopted header, so the fix is either a wrapper in your own code or a deviation under the adopted-code GRP, not a rewrite of the vendor’s file.
- Assuming generated code is exempt. Code from modelling tools is adopted code with its own rules, and, according to tool vendors’ summaries of MISRA C:2025, the current edition makes explicit that AI-generated code is held to exactly the same guidelines as handwritten code. The source of a line does not change its obligations.
What I take away
Compliance is a claim you can defend, not a number of warnings. Four documents, a GRP, a GEP, deviation records and a GCS, carry it. If they are honest and consistent, a non-zero finding count is fine.
Negotiate early, not late. The GRP and the deviation permits are agreed with the customer at the start. Every disagreement you settle in week one is a disagreement you do not have at delivery.
Make rules stricter where it is cheap. The framework lets you promote guidelines but never demote required ones. Promoting the rules you never break anyway costs nothing and makes the deviations that remain meaningful.
Let the tool do the decidable work, and plan for the rest. Single-file decidable rules belong in the editor; system rules in CI; undecidable findings and directives need named people and a review step.
Legacy code needs a ratchet, not a rewrite. Review the baseline once, gate new code hard, and let the old findings shrink as you touch the code for other reasons.
A deviation is engineering, not an excuse. Written well, with a reason, alternatives considered and precautions, it documents a real design decision. Written badly, it hides a defect with a signature on it.
Sources
- MISRA: MISRA Compliance:2020, Achieving compliance with MISRA Coding Guidelines (February 2020). The compliance framework, categories, re-categorization rules, message categories, deviation reasons, adopted code and compliance levels in this post come from this document.
- MISRA: Publications and frequently asked questions, for the list of editions and the status of MISRA C:2025
- MISRA: MISRA C:2012 Amendment 4 (March 2023), for the amendment history
- Wikipedia: MISRA C, for guideline counts of the 1998, 2004 and 2012 editions
- Perforce: What developers need to know about MISRA C:2025 and MISRA C and C++ overview, for the MISRA C:2023 count and C:2025 changes
- LDRA: The MISRA language guidelines and MISRA C:2025, the whys and wherefores
- Qt Group (Axivion): MISRA C:2025, a closer look at some of the changes, for the new rules and the statement on AI-generated code
- Featured image: ANOOF C, Unsplash (free to use under the Unsplash License)
- Figures: my own drawings; figure 7 uses invented numbers