For the first two editions of MISRA-C 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:
ISO 26262Functional 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 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, 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 a C integer may vary but an INT16 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.
MISRA C:2012 separately classifies each guideline as either Single Translation Unit or System.
Decidability
MISRA C:2012 classifies the rules 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, 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" ; 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 MISRA C:2012 - Amendment 1: Additional Security Guidelines which added fourteen new security guidelines.
Supporting Documents
MISRA have published the following addenda to support MISRA C:2012:
MISRA C:2012 - Addendum 1: Rule Mappings, which contains bi-directional rule mappings between MISRA C:2004 and the new version. It is intended to assist users in migration.
MISRA C:2012 - Addendum 2: Coverage of MISRA C:2012 against ISO/IEC TS 17961:2013 "C Secure"
MISRA C:2012 - Addendum 3: Coverage of MISRA C:2012 against CERT C
Example suite
An exemplar suite is available from the MISRA GitLab repository. This allows tool-users to evaluate and compare the checking support provided by the various MISRA tools; additionally, it gives tool-implementers some guidance as to the intent of the MISRA Guidelines.
Tools
While there exist many software tools that claim to check code for "MISRA conformance", there is no MISRA certification process. Most of the guidelines can be checked using tools that perform static code analysis. The remaining guidelines require the use of dynamic code analysis. Tools that check code for MISRA conformance include:
Some research results question the effectiveness of MISRA. In a paper that compares earlier work on MISRA C:1998 with MISRA C:2004, Les Hatton comes to the conclusion that: He goes on to state: A study at the TU Delft, by Cathal Boogerd and Leon Moonen, empirically assesses the value of MISRA C:2004. It comes to similar results: