Home / Learn Chip Programming / Coding Standards: MISRA C, Naming and Safe Style
Coding Standards: MISRA C, Naming and Safe Style
Rules that keep C code safe in cars, medical devices and aircraft.
In shortRules that keep C code safe in cars, medical devices and aircraft.
Theory in plain words
What it is
MISRA C is a set of rules limiting risky C features. CERT C and the Barr group standard are similar. Teams also add naming and formatting rules.
Why we use it
Employers in automotive, medical and industrial work expect rules-based coding. Style rules prevent whole classes of bugs.
How it works
Use static analysis (cppcheck, clang-tidy, PC-lint) and compiler warnings. Review in pull requests. Document deviations.
Where it is used
- Automotive ISO 26262, medical IEC 62304
- Code reviews and interviews
- Open source firmware quality
Spot the rule violations
Review this codeTry it Yourself
Static analysers find all of these automatically.
| Tool | Use |
|---|---|
| gcc -Wall -Wextra -Wconversion | warnings in every build |
| cppcheck | free static analysis |
| clang-tidy | style and bug checks |
| clang-format | automatic formatting |
| PC-lint, Polyspace, Coverity | commercial MISRA checking |
- Name:
module_function(),UPPER_CASEmacros,_ttypes. - One function does one job and fits on one screen.
- Comment why, not what.
- Keep ISRs short: set a flag, return.
Quick quiz
1. A common MISRA rule about if statements is...
Braces prevent the dangling-statement bug.
2. Which tool is free static analysis?
cppcheck finds many C bugs.