Rule 20.8 and #elif

Moderators: misra-c, david ward

Post Reply
rgamble
Posts: 14
Joined: Fri Jul 20, 2007 7:54 pm

Rule 20.8 and #elif

Post by rgamble » Wed Nov 01, 2017 4:03 pm

It is pretty clear from the Amplification that this is not a violation of Rule 20.8:

Code: Select all

#if 0
  #if 10  /* not evaluated, not a violation */
  #endif
#endif
and that this is:

Code: Select all

#if 0
#elif 20  /* evaluated, violation */
#endif
but is the following intended to be a violation of this rule?:

Code: Select all

#if 1
#elif 20  /* ??? */
#endif
It is not clear if the preprocessing directive #elif 20 is evaluated for the purpose of this rule.

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

Re: Rule 20.8 and #elif

Post by misra-c » Thu Nov 23, 2017 8:41 am

Code: Select all

#if 1
#elif 20  /* rule 20.8 does not apply */
#endif
The #elif is considered to be in the code that is excluded and does not affect whether the code is excluded or not. Therefore the rule does not apply to the #elif controlling expression.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.20 Preprocessing directives”