Is a function parameter “used” if cast to void?

Moderators: misra-c, david ward

Post Reply
misra-c
Posts: 548
Joined: Thu Jan 05, 2006 1:11 pm

Is a function parameter “used” if cast to void?

Post by misra-c » Thu Oct 09, 2014 9:29 am

Does the following violate rule 2.7 (There should be no unused parameters in functions)?

Code: Select all

void fn ( int32_t param )
{
   ( void )param;
}
---
Posted by and on behalf of
the MISRA C Working Group

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

Re: Is a function parameter “used” if cast to void?

Post by misra-c » Thu Oct 09, 2014 9:29 am

param is an operand of the cast operator and so is "used" according to the definition of “used” in Appendix J.

Therefore this code does not violate rule 2.7. This is consistent with the exception to rule 2.2 on dead code, which states “ A cast to void is assumed to indicate a value that is intentionally not being used.”
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.2 Unused code”