
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.
57 lines
1.7 KiB
Plaintext
57 lines
1.7 KiB
Plaintext
== Why is this an issue?
|
|
|
|
When the inclusion and exclusion of blocks of statements is controlled by a series of preprocessor directives, confusion can arise if all of the relevant directives do not occur within one file. This rule requires that all preprocessor directives in a sequence of the form ``++#if++`` / ``++#ifdef++`` ... ``++#elif++`` ... ``++#else++`` ... ``++#endif++`` shall reside in the same file. Observance of this rule preserves good code structure and avoids maintenance problems.
|
|
|
|
|
|
Notice that this does not preclude the possibility that such directives may exist within included files provided that all directives that relate to the same sequence are located in one file.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
// file1.hpp
|
|
...
|
|
#endif // Noncompliant
|
|
|
|
// file.cpp
|
|
#if 1 // Noncompliant
|
|
#include "file1.hpp"
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
// file1.hpp
|
|
#if 1 // Compliant
|
|
...
|
|
#endif // Compliant
|
|
|
|
// file.cpp
|
|
#ifdef 1 // Compliant
|
|
#include "file1.hpp"
|
|
#endif // Compliant
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA C:2004, 19.17 - All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related.
|
|
* MISRA {cpp}:2008, 16-1-2 - All #else, #elif and #endif preprocessor directives shall reside in the same file as the #if or #ifdef directive to which they are related.
|
|
* MISRA C:2012, 20.14 - All #else, #elif and #endif preprocessor directives shall reside same file as the #if, #ifdef or #ifndef directive to which they are related
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
This ["#else"|"#elif"|"#endif"] is missing a corresponding "#if" or "#ifdef" directive.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|