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.WRONGNAME.C99.2012

A macro shall not be defined with the same name as a keyword

MISRA C 2012 Rule 20.4: A macro shall not be defined with the same name as a keyword

C90 [Undefined 56], C99 [Undefined 98]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule applies to all keywords, including those that implement language extensions.

Rationale

Using macros to change the meaning of keywords can be confusing. The behaviour is undefined if a standard header is included while a macro is defined with the same name as a keyword.

The following example is non-compliant because it alters the behaviour of the int keyword. Including a standard header in the presence of this macro results in undefined behaviour.

Example

#define int some_other_type 
#include <stdlib.h>

The following example shows that it is non-compliant to redefine the keyword while but it is compliant to define a macro that expands to statements.

#define while( E ) for ( ; ( E ) ; )   /* Non-compliant - redefined while */ 
#define unless( E ) if ( ! ( E ) )     /* Compliant */

#define seq( S1, S2 ) do { \
   S1; S2; } while ( false )           /* Compliant */ 
#define compound( S ) { S; }           /* Compliant */

The following example is compliant in C90, but not C99, because inline is not a keyword in C90.

/* Remove inline if compiling for C90 */ 
#define inline

See also

Rule 21.1