Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction
Reliability Coding Guidelines
Applications
Further readings
Vittorio Giovara
Politecnico di Torino
Software Engineering
03/10/2008
1 Introduction
What is MISRA C
Software Reliability Program
2 Reliability Coding Guidelines
Overview
Rules in Practice
Extract from the guidelines
Code Examples
3 Applications
Tools
Criticsm
4 Further readings
MISRA C
It is a software development standard for the C programming
language. Its aims are to facilitate code portability and reliability
in the context of embedded systems, specifically those systems
programmed in ANSI C.
Versions
Versions
Supported standards
Only ANSI C90 standard is supported, there is no plan for an
update to the more modern standard C99.
General point
Rules examples
Character encoding
Object Identifiers
f() is the only function that references a file scope static. The
definition of use_me could be moved to a file scope static.
g() might be the only function in the translation unit that accesses a
file scope object. But the linkage is external, so functions in other
translation units might access it Define it within the function as an
extern int you say. Nope. This has all sorts of potentially nasty
undefined behaviours (interestingly not covered by the MISRA C
document).
In the codeblock the object local is only accessed within one block.
The definition could be moved to the start of that block; such
movement would be consistent with the intent of this rule in reducing
the visibility of identifiers.
Logical operators
Loop blocks
flag=1;
for (si=0; (si<5) && (flag==1); si++){
flag=0; /* OK, even if it is a loop control variable */
si=si+3; /* NOT OK, it is involved in the loop variables */
}
flag=0;
for (si=0; flag==0 ; ei++){
si += 2; /* OK */
if (si < ei){
flag = 1; /* OK */
}
}
Relational operators
Starting conditions:
The Not passing code is also not C compliant, the C complier should print
warnings.
pi_1=ai_1+2;
pi_2=ai_1+si;
Static Analyzers
The Static Analyzers check the code by parsing the source code of
the program and applying MISRA rules over it. Most of them support
both version 1998 and 2004 of the MISRA C guidelines.
Compile Analyzers