加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 03:39:44 所属栏目:百科 来源:网络整理
导读:如果我使用 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; 有没有办法可以在顶部省略那些额外的行? 解
如果我使用 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 switch和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.

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读