有没有办法省略C-preprocessor输出顶部的定义(行标记)?

前端之家收集整理的这篇文章主要介绍了有没有办法省略C-preprocessor输出顶部的定义(行标记)?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我使用 gcc -C -x c -E test.def处理以下test.def输入文件
#define TEST foo 
int TEST;

我希望输出只是:

int foo;

相反,我得到:

# 1 "test.def"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.def"

int foo;

有没有办法可以在顶部省略那些额外的行?

解决方法

这些不仅仅位于顶部 – 而是它们是C预处理器用于将某些行来自的源代码位置传递给C编译器的行标记.

使用GCC这很简单,如GCC supports the -P switchso 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.

因此,使用gcc -E -P -x c.

另外,我不会使用-C(保留注释),因为它似乎与它一起gcc从隐式头文件添加了一些注释.

原文链接:https://www.f2er.com/c/110652.html

猜你在找的C&C++相关文章