运行"光" preprocessor为GCC [英] Run a "light" preprocessor for GCC
问题描述
有没有一种方法来运行 GCC preprocessor,但仅限于用户可定义的宏?
Is there a way to run the GCC preprocessor, but only for user-defined macros?
我有几个单行有的 #IFDEF
等条件语句,我想看看我的code相时,只是那些被扩展样。
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.
由于它是,包括得到扩展,我的 fprintf中(标准错误)转成
等
取值fprintf中(((__ getreeent()) - GT; _stderr)
As it is, the includes get expanded, my fprintf(stderr)
s turn into fprintf(((__getreeent())->_stderr)
, etc.
推荐答案
呼叫 CPP
直接,例如。
$ cat >foo.c <<EOF
#define FOO
#ifdef FOO
foo is defined
#else
foo is not defined
#endif
EOF
$ cpp foo.c
# 1 "foo.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "foo.c"
foo is defined
当然,如果包括头那么这些将被包含在输出中。为了避免可能的一种方式,只是的grep -v
出与的#include
行S(或者只是那些与的#include&LT;
,并允许的#include
)或者,您可以指定 - nostdinc
选项删除只是标准的包括(但在当地的图书馆可能离开,除非您指定包含路径,使它们不会被发现) - 这会警告缺少头,虽然
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.
编辑:或者使用preprocessor本身,使头有条件的纳入,将它们包装在类似的#ifndef TESTING_ prePROCESSOR
,并使用 -DTESTING_ prePROCESSOR
。
Or use the preprocessor itself to make the inclusion of headers conditional, wrap them in something like #ifndef TESTING_PREPROCESSOR
and use -DTESTING_PREPROCESSOR
.
这篇关于运行&QUOT;光&QUOT; preprocessor为GCC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!