03-01-2013, 06:59 AM
An identifier with external linkage shall have exactly one definition.
The test exemplar provided with MISRA C for rule 8.9 has
// mc2_0809_1.c
int32_t two_different_definitions = 1; /* Not Compliant - two definitions */
// mc2_0809_2.c
int32_t two_different_definitions = 2; /* Not Compliant - two definitions */
// mc2_0809.h
extern int32_t two_different_definitions;
But the example given in the MISRA C++ Guidelines Draft for Rule 3-2-4 is :
// file1.cpp
int32_t i = 0;
// file2.cpp
int32_t i = 1; // Non-compliant
As both the rules are some what same, but the difference in the example given is that in rule 3-2-4 no external linkage is provided. Is it an incomplete example or the rule should show violation without having an extern of the variable.
The test exemplar provided with MISRA C for rule 8.9 has
// mc2_0809_1.c
int32_t two_different_definitions = 1; /* Not Compliant - two definitions */
// mc2_0809_2.c
int32_t two_different_definitions = 2; /* Not Compliant - two definitions */
// mc2_0809.h
extern int32_t two_different_definitions;
But the example given in the MISRA C++ Guidelines Draft for Rule 3-2-4 is :
// file1.cpp
int32_t i = 0;
// file2.cpp
int32_t i = 1; // Non-compliant
As both the rules are some what same, but the difference in the example given is that in rule 3-2-4 no external linkage is provided. Is it an incomplete example or the rule should show violation without having an extern of the variable.
<t></t>