我有以下代码的#define,#ifdef来和#undef #ENDIF
#define PROC_ADD
void main(void)
{
while(1)
{
#ifdef PROC_ADD
// Do this code here then undefined it to run the code in the else
// processing work
#undef PROC_ADD
#else
// now that PROC_ADD has been undefined run this code
// processing work
#endif
}
}
然而,它将运行的代码。但在PROC_ADD
未定义后,它将不会运行else
中的代码。
我认为原因可能是您只能在编译时定义和取消定义,而不是在运行时定义。但是,我不太确定。
请注意预处理不会在运行时发生,'undef'不会在运行时发生。它发生在编译时。 – abyx 2009-11-26 07:49:13