MISRA Discussion Forums
12.6 for Preprocessor Directives? - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.12 Expressions (https://forum.misra.org.uk/forumdisplay.php?fid=39)
+---- Thread: 12.6 for Preprocessor Directives? (/showthread.php?tid=764)



12.6 for Preprocessor Directives? - gs - 05-08-2010

Was 12.6 intended to prohibit the use of the '!' operator on such code as
Code:
#if ! defined A
#endif
?

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


Re: 12.6 for Preprocessor Directives? - William Forbes - 05-08-2010

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.


Re: 12.6 for Preprocessor Directives? - gs - 05-08-2010

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


Re: 12.6 for Preprocessor Directives? - misra-c - 08-08-2010

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'.