Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA C 2004 rule 5.2 vioated on pointer as argument
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
Assuming an example such as:
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 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.)
Posted by and on behalf of the MISRA C Working Group

Forum Jump:

Users browsing this thread: 1 Guest(s)