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

Several # or ## operators in a macro definition.

MISRA-C Rule 19.12 (required): The defined preprocessor operator shall only be used in one of the two standard forms.

[Undefined 47]

The only two permissible forms for the defined preprocessor operator are:

defined( identifier )
defined identifier

Any other form leads to undefined behaviour, for example:

#if defined(X > Y) /* not compliant - undefined behaviour */

Generation of the token defined during expansion of a #if or #elif preprocessing directive also leads to undefined behaviour and shall be avoided, for example:

#define DEFINED defined
#if DEFINED(X)       /* not compliant - undefined behaviour */

MISRA-C++ Rule 16-3-1 (required): There shall be at most one occurrence of the # or ## operators in a single macro definition.

[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. This problem can be avoided by having only one occurrence of either operator in any single macro definition (i.e. one #, or one ## or neither).

Example

#define A(x)         #x        // Compliant
#define B(x, y)      x ## y    // Compliant
#define C(x, y)      # x ## y  // Non-compliant

In the following, if 'y' is joined to 'z' first then the fourth parameter of 'D' will be substituted and joined to 'x'. Alternatively, if 'x' is joined with 'y' first, then the fourth parameter of 'D' will not be substituted.

#define D(x, y, z, yz) x ## y ## z    // Non-compliant