MISRA C:2012 Rule 8.3

All declarations of an object or function shall use the same names and type qualifiers

Description

This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Default Analysis (Polyspace Bug Finder Access).

Rule Definition

All declarations of an object or function shall use the same names and type qualifiers.

Rationale

Consistently using parameter names and types across declarations of the same object or function encourages stronger typing. It is easier to check that the same function interface is used across all declarations.

Polyspace Implementation

The rule checker detects situations where parameter names or data types are different between multiple declarations or the declaration and the definition. The checker considers declarations in all translation units and flags issues that are not likely to be detected by a compiler.

Polyspace Bug Finder™ and Polyspace Code Prover™ check this coding rule differently. The analyses can produce different results.

Additional Message in Report

  • Definition of function function_name incompatible with its declaration.

  • Global declaration of function_name function has incompatible type with its definition.

  • Global declaration of variable_name variable has incompatible type with its definition.

  • All declarations of an object or function shall use the same names and type qualifiers.

Troubleshooting

If you expect a rule violation but do not see it, refer to Coding Standard Violations Not Displayed.

Examples

expand all

extern int div (int num, int den);

int div(int den, int num) { /* Non compliant */
    return(num/den);
}

In this example, the rule is violated because the parameter names in the declaration and definition are switched.

typedef unsigned short width;
typedef unsigned short height;
typedef unsigned int area;

extern area calculate(width w, height h);

area calculate(width w, width h) { /* Non compliant */
    return w*h;
}

In this example, the rule is violated because the second argument of the calculate function has data type:

  • height in the declaration.

  • width in the definition.

The rule is violated even though the underlying type of height and width are identical.

Check Information

Group: Declarations and Definitions
Category: Required
AGC Category: Required
Introduced in R2014b