This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guide.
This rule only applies to programs written in C. Objects or functions with external linkage should be declared once.
Look at the following example:
/* lib1.h */
extern int32_t var; // Declaration
/* lib2.h */
extern int32_t var; // Declaration
/* some.cpp */
#include "lib1.h"
#include "lib2.h"
In this example, the 'var' variable is declared twice: in 'lib1.h' and 'lib2.h'.
We have several ways to fix this:
/* lib.h */
extern int32_t var; // Declaration
/* lib1.h */
#include "lib.h"
/* lib2.h */
#include "lib.h"
/* some.cpp */
#include "lib1.h"
#include "lib2.h"
This diagnostic is classified as:
|