Is there a way to omit the definitions (line markers) at the top of the C-preprocessor output?

痞子三分冷 提交于 2020-02-15 07:11:13

问题


If I process the following test.def input file with gcc -C -x c -E test.def:

#define TEST foo 
int TEST;

I would like the output to be just:

int foo;

Instead I get:

# 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?


回答1:


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.


With GCC this is easy, as GCC supports the -P switch, and so does llvm Clang:

-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.

Thus, use gcc -E -P -x c.

Also, I'd not use -C (retain comments), as it seems that with it gcc adds some comments from implicit header files.



来源:https://stackoverflow.com/questions/43388850/is-there-a-way-to-omit-the-definitions-line-markers-at-the-top-of-the-c-prepro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!