ArticleslgStudy

computer science

MISRA C

MISRA C is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand MISRA C rather than just read about it. In short: MISRA C is a set of software development guidelines for the C programming language developed by The MISRA Consortium. Its aims are to facilitate code safety, security, portability and reliability in the context of embedded systems, specifically those systems programmed in ISO C / C90 / C99.

Key takeaways

  • MISRA C belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect MISRA C to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of MISRA C from memory before moving on to harder problems.

Reference excerpt

MISRA C is a set of software development guidelines for the C programming language developed by The MISRA Consortium. Its aims are to facilitate code safety, security, portability and reliability in the context of embedded systems, specifically those systems programmed in ISO C / C90 / C99. There is also a set of guidelines for MISRA C++ not covered by this article.

History Draft: 1997 First edition: 1998 (rules, required/advisory) Second edition: 2004 (rules, required/advisory) Third edition: 2012 (directives; rules, Decidable/Undecidable) MISRA compliance: 2016, updated 2020 MISRA C:2023 (MISRA C Third edition, Second revision) For the first two editions of MISRA-C (1998 and 2004) all Guidelines were considered as Rules. With the publication of MISRA C:2012 a new category of Guideline was introduced - the Directive whose compliance is more open to interpretation, or relates to process or procedural matters.

Adoption Although originally specifically targeted at the automotive industry, MISRA C has evolved as a widely accepted model for best practices by leading developers in sectors including automotive, aerospace, telecom, medical devices, defense, railway, and others. For example:

The Joint Strike Fighter project C++ Coding Standards are based on MISRA-C:1998. The NASA Jet Propulsion Laboratory C Coding Standards are based on MISRA-C:2004. IEC 81001-5-1:2021 Health software and health IT systems safety, effectiveness and security - Part 5-1: Security - Activities in the product lifecycle cites MISRA C as an example of secure coding best practices. ISO 26262 Functional Safety - Road Vehicles cites MISRA C as being an appropriate sub-set of the C language: ISO 26262-6:2011 Part 6: Product development at the software level cites MISRA-C:2004 and MISRA AC AGC. ISO 26262-6:2018 Part 6: Product development at the software level cites MISRA C:2012. The AUTOSAR General Software Specification (SRS_BSW_00007) likewise cites MISRA C: The AUTOSAR 4.2 General Software Specification requires that If the BSW Module implementation is written in C language, then it shall conform to the MISRA C:2004 Standard. The AUTOSAR 4.3 General Software Specification requires that If the BSW Module implementation is written in C language, then it shall conform to the MISRA C:2012 Standard.

Guideline classification and categorization When a new software project is started, the latest MISRA standard should be used. Previous standards are still available for use with legacy software projects that need to refer to it.

Classification Each Guideline is classified as Mandatory (new for MISRA C:2012), Required or Advisory. Furthermore, the MISRA Compliance document permits Advisory guidelines to be Disapplied.

Mandatory guidelines shall always be complied with Required guidelines shall be complied with, unless subject to a Deviation Advisory guidelines are considered good practice, but compliance is less formal.

Categorization The rules can be divided logically into a number of categories:

Avoiding possible compiler differences, for example, the size of C's int type may vary but int16_t (standardized in C99) is always 16 bits. Avoiding using functions and constructs that are prone to failure, for example, malloc may fail. Produce maintainable and debuggable code, for example, naming conventions and commenting. Best practice rules. Complexity limits.

Scope MISRA C:2012 separately classifies each guideline as either Single Translation Unit or System.

Decidability MISRA C:2012 classifies the rules (but not the directives) as Decidable or Undecidable.

Achieving compliance

MISRA compliance MISRA published documents to provide additional guidance to understand and achieve MISRA compliance.

MISRA Compliance:2016, was released by MISRA in April 2016. MISRA Compliance:2020, revised edition, was released in February 2020.

Compliance In order for a piece of software to claim to be compliant to the MISRA C Guidelines, all mandatory rules shall be met and all required rules and directives shall either be met or subject to a formal deviation. Advisory rules may be disapplied without a formal deviation, but this should still be recorded in the project documentation. Note: For compliance purposes, there is no distinction between rules and directives.

Deviations Many MISRA C rules can be characterized as guidelines because under certain condition software engineers may deviate from rules and still be considered compliant with the standard. Deviations must be documented either in the code or in a file. In addition; proof must be provided that the software engineer has considered the safety of the system and that deviating from the rule will not have a negative impact, requirements for deviations also include:

The rule deviated from. Rationale for deviation.

Published documents

MISRA C:1998 The first edition of MISRA C, "Guidelines for the use of the C language in vehicle based software", which was published in 1998 and is officially known as MISRA-C:1998. MISRA-C:1998 has 127 rules, of which 93 are required and 34 are advisory; the rules are numbered in sequence from 1 to 127.

MISRA C:2004 In 2004, a second edition "Guidelines for the use of the C language in critical systems", or MISRA-C:2004 was produced, with many substantial changes to the guidelines, including a complete renumbering of the rules. MISRA-C:2004 contains 142 rules, of which 122 are "required" and 20 are "advisory"; they are divided into 21 topical categories, from "Environment" to "Run-time failures".

MISRA C:2012

Main document In 2013, the third edition, MISRA C:2012, was published. MISRA C:2012 extends support to the C99 version of the C language (while maintaining guidelines for C90), in addition to including a number of improvements that can reduce the cost and complexity of compliance, whilst aiding consistent, safe use of C in critical systems. MISRA-C:2012 contains 143 rules and 16 "directives" (that is, rules whose compliance is more open to interpretation, or relates to process or procedural matters); each of which is classified as mandatory, required, or advisory. They are separately classified as either Single Translation Unit or System. Additionally, the rules are classified as Decidable or Undecidable.

Amendment 1 In April 2016, MISRA published (as a free download) MISRA C:2012 - Amendment 1: Additional Security Guidelines which added fourteen new security guidelines.

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with MISRA C

Start with the simplest possible case. Write down what MISRA C claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to MISRA C before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about MISRA C ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of MISRA C

In research
MISRA C appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses MISRA C in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
MISRA C is common in secondary-school and first-year university syllabi. It links to neighbouring topics C (programming language), C programming language family, Embedded systems, so understanding it makes those chapters shorter.
In everyday life
Look for MISRA C outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “MISRA C” →

How to study MISRA C in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what MISRA C means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain MISRA C out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is MISRA C in simple terms?

MISRA C is a set of software development guidelines for the C programming language developed by The MISRA Consortium. Its aims are to facilitate code safety, security, portability and reliability in the context of embedded systems, specifically those systems programmed in ISO C / C90 / C99.

Why does MISRA C matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study MISRA C?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on MISRA C.

Tags

  • C (programming language)
  • C programming language family
  • Embedded systems
  • Hinckley and Bosworth
  • History of computing in the United Kingdom
  • Programming language standards
  • Science and technology in Leicestershire

Keep exploring