Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Rule 8.3: Symbol redeclared
#1
Hello,

I am facing an issue relating to rule 8.3. I am fixing MISRA violations in the project. The following code line is where i have issue:

in one of the files in the project i have the following code line:

dies->DrvPosn_D_SvRc_Rq = get_DrvPosn_D_SvRc_Rq();

get_DrvPosn_D_SvRc_Rq() is defined in other file as below:

tm_uint8 get_DrvPosn_D_SvRc_Rq(void)
{
return cio_DrvPosn_D_SvRc_Rq;
}

When i am performing the MISRA check , i get a error at 'dies->DrvPosn_D_SvRc_Rq = get_DrvPosn_D_SvRc_Rq();' line saying that Symbol 'get_DrvPosn_D_SvRc_Rq(void)' redeclared .

All the variables have same datatype tm_uint8;

Can you point out where the issue lies?

Thank you!

Ankit
<t></t>
Reply
#2
Verify that you have exactly one declaration of

Code:
tm_uint8 get_DrvPosn_D_SvRc_Rq(void);

in your project.
If that is the case you might be dealing with a false positive from whatever static analyzer you use.
<t></t>
Reply
#3
Hello,

It is only declared once in my entire project. I am using pclint for static analysis.

Should i have a justification or is there any other way for this false positive?
<t></t>
Reply
#4
A confirmed false positive by the tool vendor does not require a justification/deviation since it is not a real violation of a particular MISRA rule but a tool bug.
Please refer to your tool vendor.
<t></t>
Reply
#5
ok. Thank you
<t></t>
Reply
#6
Sorry but i have still one question. The function is directly defined in one c file. It is not declared in any header file.

So, is it still a false positive??
<t></t>
Reply
#7
If you use the code below in more than one C file, then it´s not a false positive but a violation:

Code:
extern tm_uint8 get_DrvPosn_D_SvRc_Rq(void);

If get_DrvPosn_D_SvRc_Rq is used only in one C file it should be static.
<t></t>
Reply
#8
tm_uint8 get_DrvPosn_D_SvRc_Rq(void); is defined only once in the project as follows:

Code:
tm_uint8 get_DrvPosn_D_SvRc_Rq(void)
{
    return cio_DrvPosn_D_SvRc_Rq;
}
in one.c file

Now it is called in another c(two.c) file as follow:

Code:
dies->DrvPosn_D_SvRc_Rq = get_DrvPosn_D_SvRc_Rq();

It is used like this only in the entire project. It is not used in any other file apart from this 2 files.

So, is it a MISRA violation or false positive?
<t></t>
Reply
#9
This is even worse and should give you a compiler warning like "get_DrvPosn_D_SvRc_Rq undefined - assuming extern returning int".
In addition it violates rule 8.1 (functions shall have prototypes).
You need to fix your code.
<t></t>
Reply
#10
But i am not getting any compiler error and also no violations of MISRA rule 8.1.if i write the prototype of the function in one.h header file then this error will be resolved??

Sorry for asking many questions but i am new to MISRA and C programming.
<t></t>
Reply
#11
if i write the prototype of the function in one.h header file then will this error be resolved??
<t></t>
Reply
#12
The function call of "get_DrvPosn_D_SvRc_Rq" in two.c must be preceded by a prototype declaration in the same translation unit. Otherwise there is a violation of rule 8.1.

Rule 8.3 requires that the types in the declaration and definition of a function are the same. Your example only contains a definition of a function and so rule 8.3 does not apply.
Posted by and on behalf of the MISRA C Working Group
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)