Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

...

A common, but noncompliant, practice is to choose a reserved name for a macro used in a preprocessor conditional guarding against multiple inclusions of a header file. (see See also PRE06-C. Enclose header files in an inclusion guard.) . The name may clash with reserved names defined by the implementation of the C standard library in its headers or with reserved names implicitly predefined by the compiler even when no C standard library header is included.

...

In this noncompliant code example, the names of the file scope objects _max_limit and _limit both begin with an underscore. Because _max_limit is static, this declaration might seem to be impervious to clashes with names defined by the implementation. However, because the header <stddef.h> is included to define size_t, a potential for a name clash exists. (Note, however, that a conforming compiler may implicitly declare reserved names regardless of whether any C standard library header is explicitly included.)

In addition, because _limit has external linkage, it may clash with a symbol with of the same name defined in the language runtime library even if such a symbol is not declared in any header. Consequently, it is not safe to start the name of any file scope identifier with an underscore even if its linkage limits its visibility to a single translation unit.

...

In this noncompliant code example, because the C standard library header <inttypes.h> is specified to include <stdint.h>, the name SIZE_MAX conflicts with a standard macro of the same name, used which is used to denote the upper limit of size_t. In addition, although the name INTFAST16_LIMIT_MAX is not defined by the C standard library, it is a reserved identifier because it begins with the INT prefix and ends with the _MAX suffix (see the C Standard, 7.31.10).

...

DCL37-C-EX2: For compatibility with other compiler vendors or language standard modes, it is acceptable to create a macro identifier the that is the same as a reserved identifier so long as the behavior is idempotent, as in this example:

...

DCL37-C-EX3: As a compiler vendor or standard library developer, it is acceptable to use identifiers reserved for your implementation. Reserved identifiers may be defined by the compiler, in standard library headers , or headers included by a standard library header, as in this example declaration from the glibc standard C library implementation:

...

Tool

Version

Checker

Description

Compass/ROSE

 

 

 

ECLAIR
Include Page
ECLAIR_V
ECLAIR_V
CC2.DCL37Fully implemented

LDRA tool suite

Include Page
LDRA_V
LDRA_V

86 S, 218 S, 219 S, 580 S, 626 S

Fully Implemented

Parasoft C/C++test9.5MISRA2004-20_1_aFully implemented
Polyspace Bug FinderR2016aMISRA2012-RULE-21_1, MISRA2012 
MISRA2012-RULE-21_2
 
Partial
PRQA QA-C
Include Page
PRQA QA-C_v
PRQA QA-C_v
0602, 4600, 4601, 4602,
4603, 4604, 4605, 4606,
4607, 4608
 
SonarQube C/C++ Plugin
Include Page
SonarQube C/C++ Plugin_V
SonarQube C/C++ Plugin_V
S978 

...