Does the C preprocessor strip comments or expand macros first? [duplicate]

Unfortunately, the original ANSI C Specification specifically excludes any Preprocessor features in section 4 (“This specification describes only the C language. It makes no provision for either the library or the preprocessor.”).

The C99 specification handles this explicity, though. The comments are replaced with a single space in the “translation phase”, which happens prior to the Preprocessing directive parsing. (Section 6.10 for details).

VC++ and the GNU C Compiler both follow this paradigm – other compilers may not be compliant if they’re older, but if it’s C99 compliant, you should be safe.

Leave a Comment