MISRA Discussion Forums
Rule 5.2 : confusion - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.5 Identifiers (https://forum.misra.org.uk/forumdisplay.php?fid=32)
+---- Thread: Rule 5.2 : confusion (/showthread.php?tid=1402)



Rule 5.2 : confusion - ankitshah413 - 01-03-2018

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:
extern struct con tmp_ev;

2.c
Code:
struct con tmp_ev;
cioF_get(&tmp_ev);

3.c
Code:
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


Re: Rule 5.2 : confusion - Francois - 02-03-2018

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

Quote:1.h
Code:
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 ^^


Re: Rule 5.2 : confusion - misra-c - 16-04-2018

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.