This is the HCC Embedded Product Documentation.

HCC Embedded Main Website   |   HCC Documentation Home Page

 

 

No.

MISRA Rule

Category


GROUP 1: ENVIRONMENT

 

1.1

All code shall conform to ISO 9899:1990 Programming languages – C, amended and corrected by ISO/IEC 9899/COR1:1995, ISO/IEC 9899/AMD1:1995, and ISO/IEC 9899/COR2:1996.

Required

1.2

No reliance shall be placed on undefined or unspecified behavior.

Required

1.4

The compiler/linker shall be checked to ensure that 31 character significance and case sensitivity are supported for external identifiers.

Required


GROUP 2: LANGUAGE EXTENSIONS

 

2.1

Assembler language shall be encapsulated and isolated.

Required

2.2

Source code shall only use /* ... */ style comments.

Required

2.3

The character sequence /* shall not be used within a comment.

Required

2.4

Sections of code should not be commented out.

Required


GROUP 3: DOCUMENTATION

 

3.1

All usage of implementation-defined behavior shall be documented.

Required

3.2

The character set and the corresponding encoding shall be documented.

Required

3.3

The implementation of integer division in the chosen compiler should be determined, documented, and taken into account.

Advisory

3.4

All uses of the #pragma directive shall be documented and explained.

Required

3.6

All libraries used in production code shall be written to comply with the provisions of this document, and shall have been subject to appropriate validation.

Required


GROUP 4: CHARACTER SETS

 

4.1

Only those escape sequences that are defined in the ISO C standard shall be used.

Required

4.2

Trigraphs shall not be used.

Required


GROUP 5: IDENTIFIERS

 

5.1

Identifiers (internal and external) shall not rely on the significance of more than 31 characters.

Required

5.2

Identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide that identifier.

Required

5.3

A typedef name shall be a unique identifier.

Required

5.4

A tag name shall be a unique identifier.

Required

5.5

No object or function identifier with static storage duration should be reused.

Advisory

5.6

No identifier in one namespace should have the same spelling as an identifier in another namespace, with the exception of structure member and union member names.

Advisory

5.7

No identifier name should be reused.

Advisory


GROUP 6: TYPES

 

6.1

The plain char type shall be used only for the storage and use of character values.

Required

6.2

signed and unsigned char type shall be used only for the storage and use of numeric values.

Required

6.3

typedefs that indicate size and signedness should be used in place of the basic types.

Advisory


GROUP 7: CONSTANTS

 

7.1

Octal constants (other than zero) and octal escape sequences shall not be used.

Required


GROUP 8: DECLARATIONS AND DEFINITIONS

 

8.1

Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.

Required

8.2

Whenever an object or function is declared or defined, its type shall be explicitly stated.

Required

8.3

For each function parameter, the type given in the declaration and definition shall be identical and the return types shall also be identical.

Required

8.4

If objects or functions are declared more than once, their types shall be compatible.

Required

8.5

There shall be no definitions of objects or functions in a header file.

Required

8.6

Functions shall be declared at file scope.

Required

8.7

Objects shall be defined at block scope if they are only accessed from within a single function.

Required

8.8

An external object or function shall be declared in one and only one file.

Required

8.9

An identifier with external linkage shall have exactly one external definition.

Required

8.10

All declarations and definitions of objects or functions at file scope shall have internal linkage unless external linkage is required.

Required

8.11

The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage.

Required

8.12

When an array is declared with external linkage, its size shall be stated explicitly or defined implicitly by initialization.

Required


GROUP 9: INITIALISATION

 

9.1

All automatic variables shall have been assigned a value before being used.

Required

9.2

Braces shall be used to indicate and match the structure in the non-zero initialization of arrays and structures.

Required

9.3

In an enumerator list, the “=” construct shall not be used to explicitly initialize members other than the first, unless all items are explicitly initialized.

Required


GROUP 10:ARITHMETIC TYPE CONVERSIONS

 

10.1

The value of an expression of integer type shall not be implicitly converted to a different underlying type if:
a. it is not a conversion to a wider integer type of the same signedness, or
b. the expression is complex, or
c. the expression is not constant and is a function argument, or
d. the expression is not constant and is a return expression.

Required

10.3

The value of a complex expression of integer type shall only be cast to a type that is not wider and of the same signedness as the underlying type of the expression.

Required

10.5

If the bitwise operators ~ and << are applied to an operand of underlying type unsigned char or unsigned short, the result shall be immediately cast to the underlying type of the operand.

Required

10.6

A U suffix shall be applied to all constants of unsigned type.

Required


GROUP 11:POINTER TYPE CONVERSIONS

 

11.1

Conversions shall not be performed between a pointer to a function and any type other than an integral type.

Required

11.2

Conversions shall not be performed between a pointer to object and any type other than an integral type, another pointer to object type, or a pointer to void.

Required

11.3

A cast should not be performed between a pointer type and an integral type.

Advisory

11.4

A cast should not be performed between a pointer to object type and a different pointer to object type.

Advisory

11.5

11.5 A cast shall not be performed that removes any const or volatile qualification from the type addressed by a pointer.

Required


GROUP 12: EXPRESSIONS

 

12.1

Limited dependence should be placed on the C operator precedence rules in expressions.

Advisory

12.2

The value of an expression shall be the same under any order of evaluation that the standard permits.

Required

12.3

The sizeof operator shall not be used on expressions that contain side effects.

Required

12.4

The right-hand operand of a logical && or || operator shall not contain side effects.

Required

12.5

The operands of a logical && or || shall be primary expressions.

Required

12.6

The operands of logical operators (&&, ||, and !) should be effectively Boolean. Expressions that are effectively Boolean should not be used as operands to operators other than (&&, ||, !, =, ==, !=, and ?:).

Advisory

12.7

Bitwise operators shall not be applied to operands whose underlying type is signed.

Required

12.8

The right-hand operand of a shift operator shall lie between zero and one less than the width in bits of the underlying type of the left-hand operand.

Required

12.9

Trigraphs shall not be used. The unary minus operator shall not be applied to an expression whose underlying type is unsigned.

Required

12.10

The comma operator shall not be used.

Required

12.11

Evaluation of constant unsigned integer expressions should not lead to wrap-around.

Advisory

12.13

The increment (++) and decrement (--) operators should not be mixed with other operators in an expression.

Advisory


GROUP 13 : CONTROL STATEMENT EXPRESSIONS

 

13.1

Assignment operators shall not be used in expressions that yield a Boolean value.

Required

13.2

Tests of a value against zero should be made explicit, unless the operand is effectively Boolean.

Advisory

13.5

The three expressions of a for statement shall be concerned only with loop control.

Required

13.6

Numeric variables being used within a for loop for iteration counting shall not be modified in the body of the loop.

Required

13.7

Boolean operations whose results are invariant shall not be permitted.

Required


GROUP 14 : CONTROL FLOW

 

14.1

There shall be no unreachable code.

Required

14.2

All non-null statements shall either have at least one side effect however executed, or cause control flow to change.

Required

14.3

Before preprocessing, a null statement shall only occur on a line by itself; it may be followed by a comment, provided that the first character following the null statement is a whitespace character.

Required

14.4

The goto statement shall not be used.

Required

14.5

The continue statement shall not be used.

Required

14.6

For any iteration statement, there shall be at most one break statement used for loop termination.

Required

14.7

A function shall have a single point of exit at the end of the function.

Required

14.8

The statement forming the body of a switch, while, do ... while, or for statement shall be a compound statement.

Required

14.9

An if expression construct shall be followed by a compound statement. The else keyword shall be followed by either a compound statement or another if statement.

Required

14.10

All if ... else if constructs shall be terminated with an else clause.

Required


GROUP 15 : SWITCH STATEMENTS

 

15.0

The MISRA C switch syntax shall be used.

Required

15.1

A switch label shall only be used when the most closely-enclosing compound statement is the body of a switch statement.

Required

15.2

An unconditional break statement shall terminate every non-empty switch clause.

Required

15.3

The final clause of a switch statement shall be the default clause.

Required

15.4

A switch expression shall not represent a value that is effectively Boolean.

Required

15.5

15.5 Every switch statement shall have at least one case clause.

Required


GROUP 16 : FUNCTIONS

 

16.1

Functions shall not be defined with a variable number of arguments.

Required

16.2

Functions shall not call themselves, either directly or indirectly.

Required

16.3

Identifiers shall be given for all of the parameters in a function prototype declaration.

Required

16.4

The identifiers used in the declaration and definition of a function shall be identical.

Required

16.5

Functions with no parameters shall be declared and defined with the parameter list void.

Required

16.6

The number of arguments passed to a function shall match the number of parameters.

Required

16.7

A pointer parameter in a function prototype should be declared as pointer to const if the pointer is not used to modify the addressed object.

Advisory

16.8

All exit paths from a function with non-void return type shall have an explicit return statement with an expression.

Required

16.9

A function identifier shall only be used with either a preceding &, or with a parenthesized parameter list which may be empty.

Required

16.10

If a function returns error information, then that error information shall be tested.

Required


GROUP 17 : POINTERS AND ARRAYS

 

17.1

Pointer arithmetic shall only be applied to pointers that address an array or array element.

Required

17.2

Pointer subtraction shall only be applied to pointers that address elements of the same array.

Required

17.3

 >, >=, <, <= shall not be applied to pointer types except where they point to the same array.

Required

17.4

Array indexing shall be the only allowed form of pointer arithmetic.

Required

17.5

The declaration of objects should contain no more than two levels of pointer indirection.

Advisory

17.6

The address of an object with automatic storage shall not be assigned to another object that may persist after the first object has ceased to exist.

Required


GROUP 18 : STRUCTURES AND UNIONS

 

18.1

All structure and union types shall be complete at the end of the translation unit.

Required

18.2

An object shall not be assigned to an overlapping object.

Required

18.3

An area of memory shall not be used for unrelated purposes.

Required

18.4

Unions shall not be used.

Required


GROUP 19 : PREPROCESSING DIRECTIVES

 

19.1

#include statements in a file should only be preceded by other preprocessor directives or comments.

Advisory

19.2

Non-standard characters should not occur in header file names in #include directives.

Advisory

19.3

The #include directive shall be followed by either a <filename> or "filename" sequence.

Required

19.4

C macros shall only expand to a braced initializer, a constant, a string literal, a parenthesized expression, a type qualifier, a storage class specifier, or a do-while-zero construct.

Required

19.5

Macros shall not be #define’d or #undef ’d within a block.

Required

19.6

 #undef shall not be used.

Required

19.7

A function should be used in preference to a function-like macro.

Advisory

19.8

A function-like macro shall not be invoked without all of its arguments.

Required

19.9

Arguments to a function-like macro shall not contain tokens that look like preprocessing directives.

Required

19.10

In the definition of a function-like macro, each instance of a parameter shall be enclosed in parentheses unless it is used as the operand of # or ##.

Required

19.11

All macro identifiers in preprocessor directives shall be defined before use, except in #ifdef and #ifndef preprocessor directives and the defined() operator.

Required

19.12

There shall be at most one occurrence of the # or ## preprocessor operators in a single macro definition.

Required

19.13

The # and ## preprocessor operators should not be used.

Advisory

19.14

The defined preprocessor operator shall only be used in one of the two standard forms.

Required

19.15

Precautions shall be taken in order to prevent the contents of a header file being included twice.

Required

19.16

Preprocessing directives shall be syntactically meaningful even when excluded by the preprocessor.

Required

19.17

All #else, #elif, and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related.

Required

 

GROUP 20 : STANDARD LIBRARIES

 

20.1

Reserved identifiers, macros, and functions in the standard library shall not be defined, redefined, or undefined.

Required

20.2

The names of Standard Library macros, objects, and functions shall not be reused.

Required

20.3

The validity of values passed to library functions shall be checked.

Required

20.4

Dynamic heap memory allocation shall not be used.

Required

20.5

The error indicator errno shall not be used.

Required

20.6

The macro offset of in the stddef.h library shall not be used.

Required

20.7

The setjmp macro and the longjmp function shall not be used.

Required

20.8

The signal handling facilities of signal.h shall not be used.

Required

20.9

The input/output library stdio.h shall not be used in production code.

Required

20.10

The functions atof, atoi, and atol from the library stdlib.h shall not be used.

Required

20.11

The functions abort, exit, getenv, and system from the library stdlib.h shall not be used.

Required

20.12

The time handling functions of time.h shall not be used.

Required


GROUP 21 : RUNTIME FAILURES

 

21.1

Minimization of runtime failures shall be ensured by the use of at least one of:
a. static analysis tools/techniques
b. dynamic analysis tools/techniques
c. explicit coding of checks to handle runtime faults.

Required