运行“灯” GCC 预处理器
有没有办法运行 GCC 预处理器,但仅适用于用户定义的宏?
我有一些单行语句和一些 #ifdef
等条件语句,我想看看当这些语句展开时我的代码是什么样子的。
事实上,包含内容得到了扩展,我的 fprintf(stderr)
变成了 fprintf(((__gettreeent())->_stderr)
等。
Is there a way to run the GCC preprocessor, but only for user-defined macros?
I have a few one-liners and some #ifdef
, etc. conditionals, and I want to see what my code looks like when just those are expanded.
As it is, the includes get expanded, my fprintf(stderr)
s turn into fprintf(((__getreeent())->_stderr)
, etc.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
直接调用
cpp
,例如当然,如果您包含任何标头,那么这些标头将包含在输出中。避免这种情况的一种方法可能是仅使用
grep -v
删除带有#include
的行(或者仅使用#include <
的行)并允许#include "
)。或者您可以指定-nostdinc
选项来仅删除标准包含(但可能保留在本地库中,除非您指定包含路径以便它们赢得找不到) - 不过,这会警告缺少标头。编辑:或者使用预处理器本身来使标头的包含成为有条件的,将它们包装在类似
#ifndef TESTING_PREPROCESSOR
中并使用-DTESTING_PREPROCESSOR
。Call
cpp
directly, e.g.Of course, if you include any headers then those will be included in the output. One way to avoid that might be to just
grep -v
out the lines with#include
s (or perhaps just ones with#include <
and allow#include "
). Or you could specify the-nostdinc
option to remove just standard includes (but possibly leave in local libraries unless you specify include paths so that they won't be found) - this would warn about missing headers, though.Edit: Or use the preprocessor itself to make the inclusion of headers conditional, wrap them in something like
#ifndef TESTING_PREPROCESSOR
and use-DTESTING_PREPROCESSOR
.可以使用 unifdef、unifdefall 等工具——从代码中删除预处理器条件
One may use tools like unifdef, unifdefall — remove preprocessor conditionals from code
outputfile.c 将包含您的预处理代码,但所有宏都将被扩展。
我发现这个技巧在调试具有大量包含、编译器标志和 makefile 变量的大型系统的编译时非常有用。它将暴露没有标头保护的包含文件,以及许多其他问题。
outputfile.c will have your preprocessed code, but all macros will be expanded.
I find this trick very useful when debugging compilation of large systems with tons of includes, compiler flags, and makefile variables. It will expose include files that don't have header guards, and a bunch of other problems too.
如果您只想宏扩展并跳过
#include
处理,您可以尝试这个 repo< /a>.它是原始 pcpp 的一个分支。我添加了一个--no-include
选项来跳过#include
指令的处理。所有其他宏将根据您对pcpp
的宏输入进行处理。If you just want macro expansions and skip the
#include
handling, you can try this repo. It is a fork of the original pcpp. I added a--no-include
option to skip the handling of#include
directive. All other macros will be processed based on your marco input topcpp
.