Main Content

MISRA C:2023 Rule 5.9

Identifiers that define objects or functions with internal linkage should be unique

Since R2024a

Description

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

Rule Definition

Identifiers that define objects or functions with internal linkage should be unique.

Rationale

Identifiers that have internal linkage are accessible only in the translation unit where they are declared. These identifiers are typically declared as static. If such identifiers are nonunique, the code might become difficult to understand and lead to unexpected results.

Polyspace Implementation

Polyspace flags the static variable names that are nonunique across all translation units.

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

#include<stdint.h>
#include <assert.h>
static int testGlobal;
void foo(){
static char testGlobal;//Noncompliant	
if(1){
	static char testGlobal;//Noncompliant
}
}

In this example, the identifier testGlobal is used for declaring three variables in three different scopes. Because the identifiers are static and share a nonunique name, Polyspace flags the repetitions of the identifier.

Check Information

Group: Identifiers
Category: Advisory
AGC Category: Readability

Version History

Introduced in R2024a