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.UNDEF.WRONGNAME

Undefinition of a name from the standard library.

MISRA C 2012 Rule 21.1: #define and #undef shall not be used on a reserved identifier or reserved macro name

C90 [Undefined 54, 57, 58, 62, 71] C99 [Undefined 93, 100, 101, 104, 108, 116, 118, 130]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

This rule applies to the following:
  • Identifiers or macro names beginning with an underscore;
  • Identifiers in fi le scope described in Section 7, “Library”, of The Standard;
  • Macro names described in Section 7, “Library”, of The Standard as being defined in a standard header.
This rule also prohibits the use of #define or #undef on the identifier defined as this results in explicitly undefined behaviour.
This rule does not include those identifiers or macro names that are described in the section of the applicable C standard entitled “Future Library Directions”.The Standard states that defining a macro with the same name as:
  • A macro defined in a standard header, or
  • An identifier with file scope declared in a standard header is well-defined provided that the header is not included. This rule does not permit such definitions on the grounds that they are likely to cause confusion.
Note: the macro NDEBUG is not defined in a standard header and may therefore be#define 'd.

Rationale

Reserved identifiers and reserved macro names are intended for use by the implementation. Removing or changing the meaning of a reserved macro may result in undefined behaviour.

Example

#undef __LINE__                              /* Non-compliant - begins with _          */ 
#define _ GUARD_H 1                          /* Non-compliant - begins with _          */ 
#undef _BUILTIN_sqrt                         /* Non-compliant - the implementation
                                              * may use _BUILTIN_sqrt for other 
                                              * purposes, e.g. generating a sqrt 
                                              * instruction                            */

#define defined                              /* Non-compliant - reserved identifier    */ 
#define errno my_errno                       /* Non-compliant - library identifier     */ 
#define isneg( x ) ( ( x ) < 0 )             /* Compliant     - rule doesn't include       
                                              *                 future library 
                                              *                 directions             */

See also

Rule 20.4

Undefinition of a name from the standard library.

MISRA-C 2004 Rule 20.2 (required): The names of standard library macros, objects and functions shall not be reused.

This rule is also covered by MISRA.STDLIB.WRONGNAME, MISRA.STDLIB.WRONGNAME.UNDERSCORE AND MISRA.UNDEF.WRONGNAME.UNDERSCORE.

Where new versions of standard library macros, objects or functions are used by the programmer (e.g. enhanced functionality or checks of input values) the modified macro, object or function shall have a new name. This is to avoid any confusion as to whether a standard macro, object or function is being used or whether a modified version of that function is being used. So, for example, if a new version of the sqrt function is written to check that the input is not negative, the new function shall not be named "sqrt" but shall be given a new name.

MISRA-C++ 2008 Rule 17-0-2 (required): The names of standard library macros and objects shall not be reused.

This rule is also covered by MISRA.UNDEF.WRONGNAME.UNDERSCORE.

Rationale

Where the developer uses new versions of standard library macros or objects (e.g. to enhance functionality or add checks of input values), the modified macro or object shall have a new name. This is to avoid any confusion as to whether a standard macro or object, or a modified version of them, is being used.

Example

#define NULL ( a > b ) // Non-compliant