#include main()函数内部 [英] #include inside the main () function
问题描述
我想知道是否可能在C的 main()
函数内部包含某些内容。
I would like to know if it's possible that inside the main()
function from C to include something.
例如,在一个Cell程序中,我为cache-api.h定义了参数,稍后我要在 main()
函数中进行更改。
For instance, in a Cell program i define the parameters for cache-api.h that later in the main()
function i want to change .
我知道用 #define
定义的内容可以用 #undef
程序中的任何位置,但是在重新定义所需的参数之后,我必须再次包含cache-api.h。可能吗?
I understood that what was defined with #define
can be undefined with #undef
anywhere in the program, but after redefining my needed parameters I have to include cache-api.h again . Is that possible?
我如何才能更优雅地解决这个问题?假设我想使用 cache_rd(...)
从主存储中读取,但是在执行SPU期间类型会有所不同,我如何同时使用 #define CACHED_TYPE结构x
和 #define CACHED_TYPE结构y
在同一程序中?
How can I solve this problem more elegant ? Supposing I want to read from the main storage with cache_rd(...)
but the types would differ during the execution of a SPU, how can i use both #define CACHED_TYPE struct x
and #define CACHED_TYPE struct y
in the same program?
在此先感谢您的回答,我希望我的表达方式清楚。
Thanks in advance for the answer, i hope i am clear in expression.
推荐答案
# define
和 #include
是预处理器宏: http://zh.wikipedia.org/wiki/C_preprocessor
它们在编译前已被转换/内联。
They are converted / inlined before compilation.
要回答您的问题……不,您真的不想这样做,至少是为了下一个必须尝试并理解这一点的人一团糟。
To answer your question ... no, you really wouldn't want do do that, at least for the sake of the next guy that has to try and unscramble that mess.
这篇关于#include main()函数内部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!