Rule 2.5 and unused macro parameter

Moderators: misra-c, david ward

Post Reply
Mike Bailey
Posts: 2
Joined: Thu Feb 18, 2016 5:06 pm
Company: .

Rule 2.5 and unused macro parameter

Post by Mike Bailey » Thu Mar 12, 2020 3:04 pm

Rule 2.5 states "A project should not contain unused macro declaration".

Forum post viewtopic.php?f=216&t=1571 acknowledges that Rule 2.5 should be "A project should not contain unused macro definition", however a change to "A project should not contain unused macro identifier" would cover both the original intent and also catch the following coding error without compromising rule decidability:

Code: Select all

/* Macro containing coding error - macro parameter pin is unused */
#define SET_PIN(pin, polarity)                        \ 
               ((GPIO->PIN[pin_number] & ~PIN_Msk) |                  (polarity << PIN_POL_Pos)           )
			 
void set_something(uint32_t pin_number)
{
    const uint8_t pin_number = 0;
    const uint8_t clr_pin_number = 7;

    SET_PIN(pin_number, 1);       /* Coincidently accesses the right pin */
	
    SET_PIN(clr_pin_number, 0);   /* Accesses wrong pin due to error in macro */
}

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

Re: Rule 2.5 and unused macro parameter

Post by misra-c » Wed Apr 29, 2020 8:35 am

Thank you for your comment on rule 2.5. The MISRA-C working group will consider it for future versions.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.2 Unused code”