MISRA C 2004 rule 5.2 vioated on pointer as argument

6.5 Identifiers

Moderators: misra-c, david ward

Post Reply
Newmerlin
Posts: 1
Joined: Thu Jun 05, 2014 2:52 pm
Company: IAR Systems

MISRA C 2004 rule 5.2 vioated on pointer as argument

Post by Newmerlin » Thu Jun 05, 2014 5:32 pm

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

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

Re: MISRA C 2004 rule 5.2 vioated on pointer as argument

Post by misra-c » Fri Jun 27, 2014 8:39 am

Assuming an example such as:

Code: Select all

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.
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.)
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.5 Identifiers”