Main Content

MISRA C:2023 Rule 8.3

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

Since R2024a

Description

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.

As exceptions:

  • Using compatible versions of the same basic type does not violate this rule. For example, you can use signed, int, and signed int interchangeably.

  • Using unnamed function parameters does not violate this rule. For instance, use the declaration void foo(int a) interchangeably with the declaration void foo(int).

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.

Troubleshooting

If you expect a rule violation but do not see it, refer to Diagnose Why Coding Standard Violations Do Not Appear as Expected.

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

Version History

Introduced in R2024a