Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.DEFINE.NOT_DISTINCT.C90.2012

MISRA C 2012 Rule 5.4: Macro identifiers shall be distinct

Identifier name is too long.

C90 [Undefined 7], C99 [Unspecified 7; Undefined 28]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule requires that, when a macro is being defined, its name be distinct from:

  • the names of the other macros that are currently defined; and
  • the names of their parameters.

It also requires that the names of the parameters of a given macro be distinct from each other but does not require that macro parameters names be distinct across two different macros.

The definition of distinct depends on the implementation and on the version of the C language that is being used:

  • In C90 the minimum requirement is that the first 31 characters of macro identifiers are significant;
  • In C99 the minimum requirement is that the first 63 characters of macro identifiers are significant.
In practice, implementations may provide greater limits. This rule requires that macro identifiers be distinct within the limits imposed by the implementation.

Rationale

T

If two macro identifiers differ only in non-significant characters, the behaviour is undefined. Since macro parameters are active only during the expansion of their macro, there is no issue with parameters in one macro being confused with parameters in another macro.

If portability is a concern, it would be prudent to apply this rule using the minimum limits specified in The Standard.

Long macro identifiers may impair the readability of code. While many automatic code generation systems produce long macro identifiers, there is a good argument for keeping macro identifier lengths well below this limit.

Note: In C99, if an extended source character appears in a macro name and that character does not have a corresponding universal character, The Standard does not specify how many characters it occupies.

Example

In the following example, the implementation in question supports 31 significant case-sensitive characters in macro identifiers.

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

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

See also

Rule 5.1, 5.2, 5.5