If I want to expand a C macro, what are some good ways to do that (besides tracing it manually)?
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.
UPDATE
I tried cpp, but it seemed to only do the first pass
on:
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
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
the gtk, atk, and gdk directories are all in the current working directory, so how do I let cpp search in it?
btw, gcc -E
gives the exact same output as cpp
Update2:
The include path problem is solved by using gcc -E and passing the include directory with the -I option
Try running cpp on your source file
When trapped in a sketchy IDE, try something like
to produce
thanks to "mdematos" at http://MicroChip.com/forums/m724722.aspx
Have you tried running gcc -E multiple times until there are no longer any macros?
You want to run just the preprocessor stage of your compiler, responsible for expanding macros. For
gcc
, that's "gcc -E", but I'm not sure about other compilers.You can dump the expansion of a macro at run time like this:
The program prints:
However this yields only the full expansion. If you need single steps, Eclipse/CDT can help, but only if you teach it all the headers and compiler flags you use.