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.IDENT.DISTINCT.C99.2012

MISRA C 2012 Rule 5.2: Identifiers declared in the same scope and name space shall be distinct

C90 [ Undefined 7] , C99 [Undefined 28]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule does not apply if both identifiers are external identifiers because this case is covered by Rule 5.1.

This rule does not apply if either identifier is a macro identifier because this case is covered by Rule 5.4 and Rule 5.5.

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 are significant;
  • In C99 the minimum requirement is that the first 63 characters are significant, with each universal character or extended source character counting as a single character.

Rationale

If two identifiers differ only in non-significant characters, the behaviour is undefined.

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

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

Example

In the following example, the implementation in question supports 31 significant case-sensitive characters in identifiers that do not have external linkage. The identifier engine_exhaust_gas_temperature_local is compliant with this rule. Although it is not distinct from the identifier engine_exhaust_gas_temperature_raw, it is in a different scope. However, it is not compliant with Rule 5.3.

/*             1234567890123456789012345678901*********             Characters */ 
extern int32_t engine_exhaust_gas_temperature_raw; 
static int32_t engine_exhaust_gas_temperature_scaled;         /* Non-compliant */

void f ( void ) 
{
  /*        1234567890123456789012345678901*********                Characters */ 
  int32_t   engine_exhaust_gas_temperature_local;             /* Compliant     */ 
}

/*             1234567890123456789012345678901*********             Characters */ 
static int32_t engine_exhaust_gas_temp_raw; 
static int32_t engine_exhaust_gas_temp_scaled;                /* Compliant     */

See also

Dir 1.1, Rule 5.1, Rule 5.3, Rule 5.4, Rule 5.5