Rule 2.5 Does #undef count as a "use"

Moderators: misra-c, david ward

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

Rule 2.5 Does #undef count as a "use"

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

Rule 2.5 Is #undef considered a “use” of a macro”?
For example

Code: Select all

   #define M1 This
   #define M2 That
   #undef M1
   use( M2 );
Is 'M1' unused and therefore violate rule 2.5, or does the #undef count as a use of M1?
---
Posted by and on behalf of
the MISRA C Working Group

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

Re: Rule 2.5 Does #undef count as a "use"

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

Similarly:

Code: Select all

   #define M3 first
   #undef M3
   #define M3 second
   use( M3 );
Is the first #define of M3 unused?
---
Posted by and on behalf of
the MISRA C Working Group

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

Re: Rule 2.5 Does #undef count as a "use"

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

#undef is considered to be a use of the macro. There are no violations of rule 2.5 in these examples
---
Posted by and on behalf of
the MISRA C Working Group

xiangke
Posts: 9
Joined: Tue Apr 11, 2017 7:34 am
Company: valeo

Re: Rule 2.5 Does #undef count as a "use"

Post by xiangke » Fri Jun 09, 2017 10:47 am

Rule 2.5 Is #undef considered a “use” of a macro”?
For example
CODE: SELECT ALL
#define M1 This
#define M2 That
#undef M1
use( M2 );

Is 'M1' unused and therefore violate rule 2.5, or does the #undef count as a use of M1?

using #undef is a violation for Rule 20.5. #undef used is not appreciated for MISRA C 2012. so, For me, #undef count can not be recognized as a use of M1? the above code should is a violation for rule 2.5.

Post Reply

Return to “8.2 Unused code”