MISRA Discussion Forums
MISRA C 2004 rule 5.2 vioated on pointer as argument - 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.5 Identifiers (https://forum.misra.org.uk/forumdisplay.php?fid=32)
+---- Thread: MISRA C 2004 rule 5.2 vioated on pointer as argument (/showthread.php?tid=1061)



MISRA C 2004 rule 5.2 vioated on pointer as argument - Newmerlin - 05-06-2014

I have a customer for our compiler who is asking this question:

Rule 5.2 deals with identifiers declared with block scope that hide identifiers declared at an outer block, or file, scope. It does not apply to identifiers declared in other translation units.

extern void SerialMaster_task(void *p_arg);

Warning[Pm017]: symbol hides parameter "p_arg" (declared at line 380) - identifiers in an inner scope shall not use the same name as an identifier in an outer scope, and therefore hide the identifier (MISRA C 2004 rule 5.2)

A parameter in the *declaration* of an external subroutine does not define a symbol in the current context.

---
Can you elaborate about why the source line above invokes MISRA C 2004 rule 5.2?

Dave Bailey
IAR Systems


Re: MISRA C 2004 rule 5.2 vioated on pointer as argument - misra-c - 27-06-2014

Assuming an example such as:
Code:
void * p_arg;
extern void SerialMaster_task(void *p_arg); /* no definition in translation unit */
"p_arg" will violate rule 5.2. Identifiers with "function prototype" scope are considered to be in an "inner scope" compared to the "outer scope" of "file" scope. Note: This example will also violate rule 5.7

"function prototype" scope is defined in section 6.1.2.1 on the C90 standard.
Quote:There are four kinds of scopes: function, file block and function prototype. ( A function prototype is a declaration of a function that declares the types of its parameters.)