在 "gcc -E" 预处理代码的输出中抑制注释
Supress comments in output of "gcc -E" preprocessed code
对于一个简单的 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 $
"How can I see only the C code, without those comments ?"
您可以使用 gcc
和选项 -E -P
来删除预处理器输出的 #
行。
来自 gcc
documentation:
-P
Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.
对于一个简单的 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 $
"How can I see only the C code, without those comments ?"
您可以使用 gcc
和选项 -E -P
来删除预处理器输出的 #
行。
来自 gcc
documentation:
-P
Inhibit generation of linemarkers in the output from the preprocessor. This might be useful when running the preprocessor on something that is not C code, and will be sent to a program which might be confused by the linemarkers.