Rule 5.2 : confusion

6.5 Identifiers

Moderators: misra-c, david ward

Post Reply
ankitshah413
Posts: 14
Joined: Wed Feb 14, 2018 10:02 am
Company: Inform GmbH

Rule 5.2 : confusion

Post by ankitshah413 » Thu Mar 01, 2018 4:08 pm

Hello,

I am getting MISRA 5.2 rule violation in my project. The code for which i am getting violation is a structure that is declared as extern in one header file. The code example is as under

1.h

Code: Select all

extern struct con tmp_ev;
2.c

Code: Select all

struct con tmp_ev;
cioF_get(&tmp_ev);
3.c

Code: Select all

struct con tmp_ev;
 (void)eeF_read(CON, &tmp_ev);
I get the warning only in 2.c in the line struct con tmp_ev; saying that declaration of symbol tmp_ev hides symbol tmp_ev and not in 3.c . Both 2.c and 3.c include the 1.h header file.

I am confused why this issue is present. Can anyone help me resolve this issue?

Thank you

Francois
Posts: 9
Joined: Thu Jul 13, 2017 2:22 pm
Company: TE CONNECTIVITY

Re: Rule 5.2 : confusion

Post by Francois » Fri Mar 02, 2018 7:35 am

Hi all,
Here is my first contribution for the community :)
1.h

Code: Select all

extern struct con tmp_ev;
This line in a header is use to provide visibility/access of the structure.
More precisely, this give an access an say that the struct is define in one of the source file which include this header.

I think you problem is that you have 2 definition of your structure. One in the 2.c and one in 3.C, you may just remove one of them.
In addition, it is not recommended to shared variable in this way.
Prefer to use call operation as get/set interfaces.

Feel free to correct me if i'm wrong ^^

misra-c
Posts: 548
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 5.2 : confusion

Post by misra-c » Mon Apr 16, 2018 10:23 am

Rule 5.2 only applies to identifiers in inner scopes. It is unclear from the example whether the code in 2.c and 3.c exists at file scope or within a function.

If "struct con tmp_ev" in 2.c and 3.c appears within a function definition there will be a violation of rule 5.2.

If "struct con tmp_ev" appears at file scope, there is a violation of rule 8.9 as there are two (tentative) definitions of "struct con tmp_ev" in the project.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.5 Identifiers”