
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.
73 lines
1.2 KiB
Plaintext
73 lines
1.2 KiB
Plaintext
== Why is this an issue?
|
|
|
|
Having a single declaration of a type, object or function allows the compiler to detect incompatible types for the same entity.
|
|
|
|
|
|
Normally, this will mean declaring an external identifier in a header file that will be included in any file where the identifier is defined or used.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,cpp]
|
|
----
|
|
// header.hpp
|
|
extern int16_t a;
|
|
|
|
// file1.cpp
|
|
#include "header.hpp"
|
|
|
|
extern int16_t b;
|
|
|
|
// file2.cpp
|
|
#include "header.hpp"
|
|
extern int32_t b; // Noncompliant, compiler may not detect the error
|
|
int32_t a; // Compliant, compiler will detect the error
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,cpp]
|
|
----
|
|
// header.hpp
|
|
extern int16_t a; // Compliant, declared once in a header
|
|
extern int32_t b; // Compliant, declared once in a header
|
|
|
|
// file1.cpp
|
|
#include "header.hpp"
|
|
|
|
// file2.cpp
|
|
#include "header.hpp"
|
|
----
|
|
|
|
|
|
== Resources
|
|
|
|
* MISRA {cpp}:2008, 3-2-3
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Move the declaration of "xxx" to a header file.
|
|
|
|
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
=== relates to: S826
|
|
|
|
=== relates to: S828
|
|
|
|
=== relates to: S829
|
|
|
|
=== relates to: S831
|
|
|
|
endif::env-github,rspecator-view[]
|