
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
82 lines
2.3 KiB
Plaintext
82 lines
2.3 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Defining or declaring identifiers with reserved names may lead to undefined behavior. Similarly, defining macros, variables or functions/methods with the same names as functions from the C standard library is likely to lead to unexpected results.
|
|
|
|
|
|
Additionally, such identifiers have the potential to thoroughly confuse people who are unfamiliar with the code base, possibly leading them to introduce additional errors. Therefore reserved words and the names of C standard library functions should not be used as identifiers.
|
|
|
|
|
|
This rule applies to:
|
|
|
|
* ``++defined++``
|
|
* C standard library function names
|
|
* identifiers that contain two consecutive underscores
|
|
* identifiers that begin with an underscore, followed by an uppercase letter
|
|
* identifiers in the global namespace that start with an underscore
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
#ifndef _MY_FILE
|
|
#define _MY_FILE // Noncompliant: starts with '_'
|
|
|
|
#define FIELD__VAL(field) ##field // Noncompliant: contains "__"
|
|
|
|
int free(void *pArg, int len) { // Noncompliant: free is a standard function
|
|
int __i; // Noncompliant: starts with "__"
|
|
//...
|
|
}
|
|
#endif
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
#ifndef MY_FILE
|
|
#define MY_FILE
|
|
|
|
#define FIELD_VAL(field) ##field
|
|
|
|
int clean(void *pArg, int len) {
|
|
int i;
|
|
//...
|
|
}
|
|
#endif
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA C:2004, 20.1 - Reserved identifiers, macros and functions in the standard library, shall not be defined redefined or undefined.
|
|
* MISRA {cpp}:2008, 17-0-1 - Reserved identifiers, macros and functions in the standard library shall not be defined, redefined, or undefined.
|
|
* MISRA C:2012, 21.2 - A reserved identifier or macro name shall not be declared
|
|
* https://wiki.sei.cmu.edu/confluence/x/tNYxBQ[CERT, DCL37-C.] - Do not declare or define a reserved identifier
|
|
* https://wiki.sei.cmu.edu/confluence/x/Q30-BQ[CERT, DCL51-CPP.] - Do not declare or define a reserved identifier
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Change the reserved name 'xxxxxx' to a non-reserved one.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S980
|
|
|
|
=== on 21 Oct 2019, 18:37:40 Loïc Joly wrote:
|
|
\[~amelie.renard]: I changed the rule to make it consistent with [lex.name] in the standard. Can you check?
|
|
|
|
endif::env-github,rspecator-view[]
|