MISRA Discussion Forums

Full Version: Rule 8.3: Symbol redeclared
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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.
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?
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.
ok. Thank you
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??
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.
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?
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.
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.
if i write the prototype of the function in one.h header file then will this error be resolved??
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.