
"C++" spelled as-is can result in unexpected rendering, such as C++20 was released before C++17 renders as C20 was released before C17 Make consistent use of `[source,cpp]`.
51 lines
1.5 KiB
Plaintext
51 lines
1.5 KiB
Plaintext
== Why is this an issue?
|
|
|
|
To aid code readability, all the ``++#include++`` directives in a particular code file should be grouped together near the top of the file. The only items which may precede an ``++#include++`` in a file are other preprocessor directives or comments.
|
|
|
|
Additionally, an ``++#include++`` may appear within an `extern "C"` block, this can be used for instance to include a C file from a {cpp} file.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
#include <h1.h> /* Compliant */
|
|
int32_t i;
|
|
#include <f2.h> /* Noncompliant */
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
#include <h1.h>
|
|
#include <f2.h>
|
|
extern "C" {
|
|
#include <f3.h>
|
|
}
|
|
|
|
int32_t i;
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA C:2004, 19.1 - #include statements in a file should only be preceded by other preprocessor directives or comments.
|
|
* MISRA {cpp}:2008, 16-0-1 - #include directives in a file shall only be preceded by other preprocessor directives or comments.
|
|
* MISRA C:2012, 20.1 - #include directives should only be preceded by preprocessor directives or comments
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== on 31 Mar 2015, 19:00:55 Evgeny Mandrikov wrote:
|
|
\[~ann.campbell.2] implementation seems more complete (SQALE, description) than this spec.
|
|
|
|
=== on 13 Apr 2015, 19:35:57 Evgeny Mandrikov wrote:
|
|
\[~ann.campbell.2] I'm wondering why blocker, but not active by default? Note that in implementation currently major and active.
|
|
|
|
endif::env-github,rspecator-view[]
|