12.6 for Preprocessor Directives?

6.12 Expressions

Moderators: misra-c, david ward

Post Reply
gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

12.6 for Preprocessor Directives?

Post by gs » Thu Aug 05, 2010 2:46 pm

Was 12.6 intended to prohibit the use of the '!' operator on such code as

Code: Select all

#if ! defined A
#endif
?

Could a case not be made the result of 'defined' is an "effectively Boolean Expression"?

William Forbes
Posts: 29
Joined: Wed Dec 17, 2008 9:48 pm
Company: TRW Automotive

Re: 12.6 for Preprocessor Directives?

Post by William Forbes » Thu Aug 05, 2010 6:10 pm

I don't see why you could possibly claim that the defined preprocessing operator is not "effectively Boolean"
ISO 9899:1990 clause 6.8.1 says it return either 0 or 1.
Granted it wil be a long and not an int that a true (or at least as true as you can get in C) Boolean would be.
I don't know hat values you expect Booleans to take!
So I think a strong case can be made.

gs
Posts: 87
Joined: Thu Nov 18, 2004 1:39 am

Re: 12.6 for Preprocessor Directives?

Post by gs » Thu Aug 05, 2010 6:29 pm

Exactly, William. :-) I merely was looking for confirmation from MISRA the absence of 'defined' in the definition of "Boolean Expressions" was, perhaps, an oversight.

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

Re: 12.6 for Preprocessor Directives?

Post by misra-c » Sun Aug 08, 2010 8:33 pm

Rule 12.6 is not intended to prohibit the use of the '!' operator in this way. It can indeed be argued that the 'defined' operator yields an effectively Boolean expression and this is a fair justification for permitting '!' to be applied to the result of 'defined'.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.12 Expressions”