有没有办法忽略C预处理器输出顶部的定义(行标记)? [英] Is there a way to omit the definitions (line markers) at the top of the C-preprocessor output?
问题描述
如果我使用gcc -C -x c -E test.def
处理以下test.def
输入文件:
If I process the following test.def
input file with gcc -C -x c -E test.def
:
#define TEST foo
int TEST;
我希望输出为:
int foo;
相反,我得到了:
# 1 "test.def"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.def"
int foo;
有什么办法可以省略顶部的多余行?
Is there a way I can omit those extra lines at the top?
推荐答案
这些不仅位于顶部-而是C预处理程序用来传达某些行来自何处的源代码位置的行标记,到C编译器.
These are not just on the top - but instead they're the line markers that the C preprocessors use to convey the source code positions where certain lines come from, to the C compiler.
有了GCC,这很容易,因为 GCC支持-P
开关,和 llvm Clang也是如此:
With GCC this is easy, as GCC supports the -P
switch, and so does llvm Clang:
-P
.禁止在 预处理器.当在不是C代码的东西上运行预处理器时,这可能会很有用,并且会将其发送到可能会被行标记混淆的程序.
-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.
因此,请使用gcc -E -P -x c
.
此外,我不使用-C
(保留注释),因为gcc
似乎从隐式头文件中添加了一些注释.
Also, I'd not use -C
(retain comments), as it seems that with it gcc
adds some comments from implicit header files.
这篇关于有没有办法忽略C预处理器输出顶部的定义(行标记)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!