rspec/rules/S830/cfamily/rule.adoc

44 lines
844 B
Plaintext
Raw Normal View History

2021-04-28 16:49:39 +02:00
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.
2021-04-28 16:49:39 +02:00
== Noncompliant Code Example
----
// 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
----
2021-04-28 16:49:39 +02:00
== Compliant Solution
----
// 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"
----
2021-04-28 16:49:39 +02:00
== See
* MISRA {cpp}:2008, 3-2-3