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.SHARP

# or ## operator in a macro definition.

MISRA C 2012 Rule 20.10: The # and ## preprocessor operators should not be used

C90 [Unspecified 12; Undefined 51, 52], C99 [Unspecified 25; Undefined 3, 88, 89]

Category: Analysis

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Rationale

The order of evaluation associated with multiple #, multiple ## or a mix of # and ## preprocessor operators is unspecified. In some cases it is therefore not possible to predict the result of macro expansion.

The use of the ## operator can result in code that is obscure.

Note: Rule 1.3 covers the undefined behaviour that arises if either:

  • The result of a # operator is not a valid string literal; or
  • The result of a ## operator is not a valid preprocessing token.

See also

Rule 20.11

MISRA-C 2004 Rule 19.13 (advisory): The # and ## operators should not be used.

[Unspecified 12]

There is an issue of unspecified order of evaluation associated with the # and ## preprocessor operators. Compilers have been inconsistent in the implementation of these operators. To avoid these problems do not use them.

MISRA-C++ 2008 Rule 16-3-2 (advisory): The # and ## operators should not be used.

[Unspecified 16.3.2(2), 16.3.3(3), Undefined 16.3.2(2), 16.3.3(3)]

Rationale

The order of evaluation associated with both the # and ## preprocessor operators is unspecified. Compilers have been known to implement these operators inconsistently, therefore, to avoid these problems, do not use them.

Example

#define A(Y) #Y        // Non-compliant
#define A(X,Y) X##Y    // Non-compliant