Rule 8.3: Symbol redeclared
Moderators: misra-c, david ward
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Rule 8.3: Symbol redeclared
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
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
-
- Posts: 117
- Joined: Wed Apr 27, 2016 2:33 pm
- Company: Elektrobit Automotive GmbH
Re: Rule 8.3: Symbol redeclared
Verify that you have exactly one declaration of
in your project.
If that is the case you might be dealing with a false positive from whatever static analyzer you use.
Code: Select all
tm_uint8 get_DrvPosn_D_SvRc_Rq(void);
If that is the case you might be dealing with a false positive from whatever static analyzer you use.
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
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?
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?
-
- Posts: 117
- Joined: Wed Apr 27, 2016 2:33 pm
- Company: Elektrobit Automotive GmbH
Re: Rule 8.3: Symbol redeclared
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.
Please refer to your tool vendor.
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
ok. Thank you
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
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??
So, is it still a false positive??
-
- Posts: 117
- Joined: Wed Apr 27, 2016 2:33 pm
- Company: Elektrobit Automotive GmbH
Re: Rule 8.3: Symbol redeclared
If you use the code below in more than one C file, then it´s not a false positive but a violation:
If get_DrvPosn_D_SvRc_Rq is used only in one C file it should be static.
Code: Select all
extern tm_uint8 get_DrvPosn_D_SvRc_Rq(void);
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
tm_uint8 get_DrvPosn_D_SvRc_Rq(void); is defined only once in the project as follows:
in one.c file
Now it is called in another c(two.c) file as follow:
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?
Code: Select all
tm_uint8 get_DrvPosn_D_SvRc_Rq(void)
{
return cio_DrvPosn_D_SvRc_Rq;
}
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();
So, is it a MISRA violation or false positive?
-
- Posts: 117
- Joined: Wed Apr 27, 2016 2:33 pm
- Company: Elektrobit Automotive GmbH
Re: Rule 8.3: Symbol redeclared
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.
In addition it violates rule 8.1 (functions shall have prototypes).
You need to fix your code.
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
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.
Sorry for asking many questions but i am new to MISRA and C programming.
-
- Posts: 14
- Joined: Wed Feb 14, 2018 10:02 am
- Company: Inform GmbH
Re: Rule 8.3: Symbol redeclared
if i write the prototype of the function in one.h header file then will this error be resolved??
-
- Posts: 572
- Joined: Thu Jan 05, 2006 1:11 pm
Re: Rule 8.3: Symbol redeclared
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.
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
Posted by and on behalf of
the MISRA C Working Group