眼看扩大C宏 [英] Seeing expanded C macros
问题描述
如果我想扩展一个C宏,有什么好的方法可以做到这一点(除了跟踪它手动)?
If I want to expand a C macro, what are some good ways to do that (besides tracing it manually)?
例如, GTK_WIDGET_SET_FLAGS
,它使用使用使用宏宏宏(或两个)...
For instance, GTK_WIDGET_SET_FLAGS
, it uses a macro that uses a macro that uses a macro (or two) ...
我想只是看到它在某种程度上自动地扩大而不是搜索每一个宏的每一步。
I want to just see it somehow expanded automagically, instead of searching for every macro, every step of the way.
我试过CPP,但它似乎只能做第一遍
I tried cpp, but it seemed to only do the first pass
在
GTK_WIDGET_SET_FLAGS(obj, 13)
我得到了包括文件扩展,然后:
I got the include file expanded, and then:
G_STMT_START{ ((GTK_OBJECT_FLAGS (obj)) |= (13)); }G_STMT_END
这是由这些错误消息,我得到这个在stderr(使用时-o文件名)解释
This is explained by these error message I get this on stderr (when using -o filename)
gtk/gtkwidget.h:34:21: gdk/gdk.h: No such file or directory
gtk/gtkwidget.h:35:31: gtk/gtkaccelgroup.h: No such file or directory
gtk/gtkwidget.h:36:27: gtk/gtkobject.h: No such file or directory
gtk/gtkwidget.h:37:31: gtk/gtkadjustment.h: No such file or directory
gtk/gtkwidget.h:38:26: gtk/gtkstyle.h: No such file or directory
gtk/gtkwidget.h:39:29: gtk/gtksettings.h: No such file or directory
gtk/gtkwidget.h:40:21: atk/atk.h: No such file or directory
在GTK,ATK和GDK目录都在当前工作目录,所以我怎么让这CPP搜索?
the gtk, atk, and gdk directories are all in the current working directory, so how do I let cpp search in it?
顺便说一句,的gcc -E
给出确切相同的输出 CPP
btw, gcc -E
gives the exact same output as cpp
include路径问题是通过gcc -E并通过包括与-I选项目录解决
The include path problem is solved by using gcc -E and passing the include directory with the -I option
推荐答案
根据您所使用的编译器,应该有办法看到code中的的 preprocessor (由它来展开宏,宏不是由编译器在所有已知的)就完成了。
Depending on which compiler you use, there should be a way to see the code after the preprocessor (which does the macro expansion, macros are not known by the compiler at all) is done.
使用gcc,该选项<一个href=\"http://gcc.gnu.org/onlinedocs/gcc-4.4.0/gcc/$p$pprocessor-Options.html#$p$pprocessor-Options\">-E.这里有一个简单的例子,用玩具code,而不是实际的GTK +宏:
With gcc, the option is -E. Here's a simplified example, using toy code and not the actual GTK+ macro:
~/tmp> cat cpptest.c
#define SET_FLAGS(w, f) ((w)->flags |= (f))
int main(void)
{
SET_FLAGS(0, 4711);
return 0;
}
~/tmp> gcc -E cpptest.c
# 1 "cpptest.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "cpptest.c"
int main(void)
{
((0)->flags |= (4711));
return 0;
}
这篇关于眼看扩大C宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!