#define CAT(a,b) a##b
#define COMMENT CAT(/,/)
COMMENT This is a comment
Should it compile?
It passes MS C/C++ 13.0 (Visual Studio 2002) and fails IAR ARM
compiler.
IAR claims that comments should not be processed after macro
expansion, so I have an odd situation where the preprocessor output is
as intended and is compilable, whereas the original file is not.
What is the truth, according to the standard(s)?
(I myself can read but cannot parse 'em :)
Thank you very much,
Ark
No.
> It passes MS C/C++ 13.0 (Visual Studio 2002) and fails IAR ARM
> compiler.
> IAR claims that comments should not be processed after macro
> expansion, so I have an odd situation where the preprocessor output is
> as intended and is compilable, whereas the original file is not.
>
> What is the truth, according to the standard(s)?
> (I myself can read but cannot parse 'em :)
Comments are removed in translation phase 3. Macros
are expanded in phase 4.
"The preprocessor output" is really just a sort of
courtesy many compilers extend. The Standard does not
require that such output be obtainable, and certainly
doesn't require that the output (if any) have the same
meaning as the code from which it was produced. This
is a case of the latter situation: The preprocessed
output is valid C, but the source from which it was
generated is not.
Problem is that windows header files use this feature to
selectiveley comment out portions of the code
according to macro definitions embedded in
#ifdefs, well the usual stuff.
This was one of the many problems with those headers.
They tend to be very Microsoft specific.
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.722 / Virus Database: 478 - Release Date: 7/21/2004