[previous] MISRA C:2012  Rule-21.1:  (Required) [next] #define and #undef shall not be used on a reserved identifier or reserved macro name

Amplification:

This rule applies to the following:

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:

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.

Example Code:


#include "misra.h"
#include "m3cmex.h"


#define defined ! defined       /* 0836      */


#undef __LINE__                 /* 0848 0841 */
#undef __FILE__                 /* 0848 0841 */
#undef __DATE__                 /* 0848 0841 */
#undef __TIME__                 /* 0848 0841 */
#undef __STDC__                 /* 0848 0841 */

#define __LINE__ 1              /* 0854 0602 */
#define __FILE__ "default"      /* 0854 0602 */
#define __DATE__ "01-01-2000"   /* 0854 0602 */
#define __TIME__ "00:00:00"     /* 0854 0602 */
#define __STDC__                /* 0854 0602 */

#define NULL (void *)0          /* 4600      */
#define EDOM 22                 /* 4600      */
#define tan 1                   /* 4601      */
#define printf xprintf          /* 4601      */


extern int16_t rule_2101( void )
{
   return 1;
}


QAC messages that encompass this guideline:

0836 [U] Definition of macro named 'defined'.
0848 [U] Attempting to #undef '%s', which is a predefined macro name.
0854 [U] Attempting to #define '%s', which is a predefined macro name.
4600 The macro '%1s' is also defined in '<%2s>'.
4601 The macro '%1s' is the name of an identifier in '<%2s>'.


Related rules:

Rule-1.3 There shall be no occurrence of undefined or critical unspecified behaviour



(c) The Motor Industry Research Association, 2012
QA C Source Code Analyser 8.1.2
MISRA C:2012 Compliance Module 1.0
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA C:2012 Rule Index Contents