MISRA C:2012 Rule 5.5

Identifiers shall be distinct from macro names

Description

Rule Definition

Identifiers shall be distinct from macro names.

Rationale

The rule requires that macro names that exist only prior to processing must be different from identifier names that also exist after preprocessing. Keeping macro names and identifiers distinct help avoid confusion.

Polyspace Implementation

Polyspace® considers two names as distinct if there is a difference between their first 63 characters. In C90, the difference must occur between the first 31 characters. To use the C90 rules checking, use the value c90 for the option -c-version (see Polyspace Server documentation). You can change the number of characters compared using the option -code-behavior-specifications. See -code-behavior-specifications (Polyspace Code Prover Server).

Additional Message in Report

Identifier XX has same significant characters as macro YY.

Troubleshooting

If you expect a rule violation but do not see it, refer to the documentation of Polyspace Code Prover™ or Polyspace Code Prover Server™.

Examples

expand all

#define Sum_1(x, y) ( ( x ) + ( y ) )
short Sum_1;                    /* Non-compliant */

#define Sum_2(x, y) ( ( x ) + ( y ) )
short x = Sum_2 ( 1, 2 );       /* Compliant */

In this example, Sum_1 is both the name of an identifier and a macro. Sum_2 is used only as a macro.

#define low_pressure_turbine_temperature_1 lp_tb_temp_1
static int low_pressure_turbine_temperature_2;   /* Non-compliant  */

In this example, the identifier low_pressure_turbine_temperature_2 has the same first 31 characters as a previous macro low_pressure_turbine_temperature_1.

Check Information

Group: Identifiers
Category: Required
AGC Category: Required
Introduced in R2014b