Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 5.2 : confusion

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

extern struct con tmp_ev;

struct con tmp_ev;

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
Hi all,
Here is my first contribution for the community :)

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 ^^
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

Forum Jump:

Users browsing this thread: 1 Guest(s)