Rule 8.3: Symbol redeclared - Printable Version +- MISRA Discussion Forums (https://forum.misra.org.uk) +-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4) +--- Forum: MISRA-C: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17) +---- Forum: 6.8 Declarations and Definitions (https://forum.misra.org.uk/forumdisplay.php?fid=35) +---- Thread: Rule 8.3: Symbol redeclared (/showthread.php?tid=1399) |
Rule 8.3: Symbol redeclared - ankitshah413 - 16-02-2018 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 Re: Rule 8.3: Symbol redeclared - dg1980 - 19-02-2018 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. Re: Rule 8.3: Symbol redeclared - ankitshah413 - 19-02-2018 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? Re: Rule 8.3: Symbol redeclared - dg1980 - 19-02-2018 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. Re: Rule 8.3: Symbol redeclared - ankitshah413 - 19-02-2018 ok. Thank you Re: Rule 8.3: Symbol redeclared - ankitshah413 - 21-02-2018 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?? Re: Rule 8.3: Symbol redeclared - dg1980 - 21-02-2018 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. Re: Rule 8.3: Symbol redeclared - ankitshah413 - 21-02-2018 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) 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? Re: Rule 8.3: Symbol redeclared - dg1980 - 21-02-2018 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. Re: Rule 8.3: Symbol redeclared - ankitshah413 - 21-02-2018 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. Re: Rule 8.3: Symbol redeclared - ankitshah413 - 23-02-2018 if i write the prototype of the function in one.h header file then will this error be resolved?? Re: Rule 8.3: Symbol redeclared - misra-c - 16-04-2018 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. |