微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有办法省略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.jb51.cc/c/110652.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐