Rule 8.3: Symbol redeclared

6.8 Declarations and Definitions

Moderators: misra-c, david ward

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

Rule 8.3: Symbol redeclared

Post by ankitshah413 » Fri Feb 16, 2018 12:34 pm

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

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 8.3: Symbol redeclared

Post by dg1980 » Mon Feb 19, 2018 8:51 am

Verify that you have exactly one declaration of

Code: Select all

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.

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Mon Feb 19, 2018 10:04 am

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?

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 8.3: Symbol redeclared

Post by dg1980 » Mon Feb 19, 2018 10:09 am

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.

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Mon Feb 19, 2018 10:31 am

ok. Thank you

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Wed Feb 21, 2018 10:35 am

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

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 8.3: Symbol redeclared

Post by dg1980 » Wed Feb 21, 2018 11:40 am

If you use the code below in more than one C file, then it´s not a false positive but a violation:

Code: Select all

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.

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Wed Feb 21, 2018 11:57 am

tm_uint8 get_DrvPosn_D_SvRc_Rq(void); is defined only once in the project as follows:

Code: Select all

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: Select all

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?

dg1980
Posts: 109
Joined: Wed Apr 27, 2016 2:33 pm
Company: Elektrobit Automotive GmbH

Re: Rule 8.3: Symbol redeclared

Post by dg1980 » Wed Feb 21, 2018 12:07 pm

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.

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Wed Feb 21, 2018 12:35 pm

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.

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

Re: Rule 8.3: Symbol redeclared

Post by ankitshah413 » Fri Feb 23, 2018 8:17 am

if i write the prototype of the function in one.h header file then will this error be resolved??

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

Re: Rule 8.3: Symbol redeclared

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

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

Post Reply

Return to “6.8 Declarations and Definitions”