Main Content

MISRA C:2012 Rule 5.4

Macro identifiers shall be distinct

Description

Rule Definition

Macro identifiers shall be distinct.

Rationale

The names of macro identifiers must be distinct from both other macro identifiers and their parameters.

Polyspace Implementation

The checker raises a violation if two macros that have the same first 63 characters are defined with different values. The checker does not raise a violation if the same macro is defined with different values but the macro is undefined in between.

The cutoff of 63 characters applies to a C99-based analysis. In C90, the cutoff is 31 characters. In other words, the checker considers two macros as effectively the same if there is no difference in their first 31 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.

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

#define engine_exhaust_gas_temperature_raw egt_r
#define engine_exhaust_gas_temperature_scaled egt_s   /* Non-compliant */

#define engine_exhaust_gas_temp_raw egt_r
#define engine_exhaust_gas_temp_scaled egt_s          /* Compliant */

In this example, the macro engine_exhaust_gas_temperature_scaled egt_s has the same first 31 characters as a previous macro engine_exhaust_gas_temperature_scaled.

#define engine_xxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_raw egt_r
#define engine_xxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_raw_scaled egt_s /* Non-compliant */

/* 63 significant case-sensitive characters in macro identifiers */
#define new_engine_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_raw egt_r
#define new_engine_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_scaled egt_s /* Compliant */

In this example, the macro engine_xxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx___gaz_scaled has the same first 63 characters as a previous macro engine_xxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx_xxxxxxxxx___raw.

Check Information

Group: Identifiers
Category: Required
AGC Category: Required

Version History

Introduced in R2014b