Main Content

MISRA C:2012 Rule 5.1

External identifiers shall be distinct

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

External identifiers shall be distinct.

Rationale

External identifiers are ones declared with global scope or storage class extern.

If the two long names are almost identical and differ only in the later part, they can be easily mistaken for each other. The readability of the code is reduced.

Polyspace Implementation

Polyspace considers two names as distinct if there is a difference between their first 31 characters. For C90, the difference must occur between the first 6 characters. To use the C90 rules checking, use the value c90 for the option C standard version (-c-version). You can change the number of characters compared using the option -code-behavior-specifications. See -code-behavior-specifications.

Additional Message in Report

External %s %s conflicts with the external identifier XX in file YY.

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

int engine_temperature_raw;
int engine_temperature_scaled;   /* Noncompliant */					
int engin2_temperature;          /* Compliant */	

In this example, the identifier engine_temperature_scaled has the same first six characters as a previous identifier, engine_temperature_raw.

int engine_exhaust_gas_temperature_raw;
int engine_exhaust_gas_temperature_scaled; /* Noncompliant */					

int eng_exhaust_gas_temp_raw;
int eng_exhaust_gas_temp_scaled;           /* Compliant */						

In this example, the identifier engine_exhaust_gas_temperature_scaled has the same first 31 characters as a previous identifier, engine_exhaust_gas_temperature_raw.

/* file1.c */
int abc = 0; /* Noncompliant */
/* file2.c */
int ABC = 0; 

In this example, the implementation supports 6 significant case-insensitive characters in external identifiers. The identifiers in the two translation are different but are not distinct in their significant characters.

Check Information

Group: Identifiers
Category: Required
AGC Category: Required

Version History

Introduced in R2014b