GCC 预处理器删除注释

AOO*_*AOO 4 gcc c-preprocessor

是否可以指示 GCC 预处理器在处理文件时不删除注释?

The*_*zoo 6

GCC 有 -C 选项来保留注释。

`-C'
     Do not discard comments.  All comments are passed through to the
     output file, except for comments in processed directives, which
     are deleted along with the directive.

     You should be prepared for side effects when using `-C'; it causes
     the preprocessor to treat comments as tokens in their own right.
     For example, comments appearing at the start of what would be a
     directive line have the effect of turning that line into an
     ordinary source line, since the first token on the line is no
     longer a `#'.
Run Code Online (Sandbox Code Playgroud)

  • “副作用”,例如在顶部插入巨大的 gcc 许可证序言。 (2认同)

CB *_*ley 2

是的,您可以使用该-C选项来做到这一点。例如

gcc -C -E myfile.c
Run Code Online (Sandbox Code Playgroud)