在"gcc -E"预处理代码的输出中抑制注释

sps*_*sps 2 c gcc c-preprocessor

对于一个简单的C程序,我gcc -E hello.c -o hello.pp看到了预处理后程序的外观.

在输出文件中,我可以看到许多行开头#,看起来像注释.这些线是什么?

如果没有这些注释,我怎么能只看到C代码?

以下是一个片段:

user $ gcc -E hello.c -o hello.pp
user $ tail -n 15 hello.pp

extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ;

extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__));
# 943 "/usr/include/stdio.h" 3 4

# 3 "hello.c" 2
int main() 
{
     printf("Hello world \n");

     return 0;
}
user $ 
Run Code Online (Sandbox Code Playgroud)

oua*_*uah 6

"如果没有这些评论,我怎么才能看到C代码呢?"

您可以使用gcc选项-E -P来摆脱#预处理器输出的行.

来自gcc 文档:

-P

禁止在预处理器的输出中生成线标记.当在非C代码上运行预处理器时,这可能很有用,并且会被发送到可能被行标记混淆的程序.