MISRA Discussion Forums
Rule 20.8 and #elif - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.20 Preprocessing directives (https://forum.misra.org.uk/forumdisplay.php?fid=175)
+---- Thread: Rule 20.8 and #elif (/showthread.php?tid=1385)



Rule 20.8 and #elif - rgamble - 01-11-2017

It is pretty clear from the Amplification that this is not a violation of Rule 20.8:
Code:
#if 0
  #if 10  /* not evaluated, not a violation */
  #endif
#endif
and that this is:
Code:
#if 0
#elif 20  /* evaluated, violation */
#endif
but is the following intended to be a violation of this rule?:
Code:
#if 1
#elif 20  /* ??? */
#endif
It is not clear if the preprocessing directive #elif 20 is evaluated for the purpose of this rule.


Re: Rule 20.8 and #elif - misra-c - 23-11-2017

Code:
#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.