![]() |
|
MISRA-C:2004 Rule 20.1: (Required) |
|
||||
![]() | |||||||
See also Rule 19.6 regarding the use of #undef.
Reserved identifiers are defined by ISO/IEC 9899:1990 [2] Sections 7.1.3 "Reserved identifiers" and 6.8.8 "Predefined macro names". Macros in the standard library are examples of reserved identifiers. Functions in the standard library are examples of reserved identifiers. Any identifier in the standard library is considered a reserved identifier in any context i.e. at any scope or regardless of header files.
The defining, redefining or undefining of the reserved identifiers defined in 7.13 "Future library directions" is advisory.
Rule 20.1 applies regardless of which, if any, header files are included.
Example Code:
/*PRQA S 862 ++ */
#include "misra.h"
#include "m2cmex.h"
#include "gen.h"
#define defined ! defined /* MISRA Violation */ /* 0836 */
#undef __LINE__ /* MISRA Violation */ /* 0848 */
#undef __FILE__ /* MISRA Violation */ /* 0848 */
#undef __DATE__ /* MISRA Violation */ /* 0848 */
#undef __TIME__ /* MISRA Violation */ /* 0848 */
#undef __STDC__ /* MISRA Violation */ /* 0848 */
#define __LINE__ 1 /* MISRA Violation */ /* 0854 */
#define __FILE__ "default" /* MISRA Violation */ /* 0854 */
#define __DATE__ "01-01-2000" /* MISRA Violation */ /* 0854 */
#define __TIME__ "00:00:00" /* MISRA Violation */ /* 0854 */
#define __STDC__ /* MISRA Violation */ /* 0854 */
#define NULL (void *)0 /* MISRA Violation */
#define tan 1 /* MISRA Violation */
#define printf xprintf /* MISRA Violation */
extern S16 test_2001( 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. |
| 3439 | Macro redefines a keyword. |
| 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.2 | No reliance shall be placed on undefined or unspecified behaviour. |
|
||
(c) The Motor Industry Research Association, 2004
|
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2 © 2013 Programming Research www.programmingresearch.com |
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index | Contents |