Rule 3-2-4 comparison with MISRA C Rule 8.9

Moderators: david ward, misra cpp

Post Reply
Posts: 1
Joined: Mon Oct 08, 2012 11:44 am
Company: Tata Research Design and Development Centre

Rule 3-2-4 comparison with MISRA C Rule 8.9

Post by sarkarsaurabh_27 » Thu Jan 03, 2013 6: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.

misra cpp
Posts: 161
Joined: Mon Jun 02, 2008 1:55 pm
Company: MISRA

Re: Rule 3-2-4 comparison with MISRA C Rule 8.9

Post by misra cpp » Mon Oct 05, 2015 2:38 pm

There is no difference in the two examples quoted.

All the variables have external linkage as variables always have external linkage, unless explicitly marked as static.
Posted by and on behalf of
the MISRA C++ Working Group

Post Reply

Return to “6.3 Basic concepts (C++)”