Clarification on Rule 20.8

Moderators: misra-c, david ward

Post Reply
anuj1085
Posts: 7
Joined: Mon Feb 09, 2015 7:17 am
Company: TCS

Clarification on Rule 20.8

Post by anuj1085 » Thu Mar 05, 2015 12:47 pm

In the below case

#if 10
----
#elif 20
----
#endif

Since the part of the code
#elif 20
----
#endif

Is never gonna execute, is the rule applicable to this part of code i.e the part #elif 20 will be ignored while compilation so should the violation should be reported on it ?

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

Re: Clarification on Rule 20.8

Post by misra-c » Fri Mar 13, 2015 9:00 am

The amplification of rule 20.8 states:
This rule does not apply to controlling expressions in preprocessing directives which are not evaluated. Controlling expressions are not evaluated if they are within code that is being excluded and cannot have an effect on whether code is excluded or not.
Therefore this rule does not apply to the "#elif 20". However the "#if 10" is a violation of rule 20.8
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.14 Control statement expressions”