3
是否有预处理程序指令检查是否未定义常量。我知道#ifndef
指令,但我也在寻找#elif not defined
指令。 #elif not defined
是否存在?预处理器指令:#elif未定义?
这是我会怎么使用它:
#define REGISTER_CUSTOM_CALLBACK_FUNCTION(callbackFunctName) \
#ifndef CUSTOM_CALLBACK_1 \
#define CUSTOM_CALLBACK_1 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#elif not defined CUSTOM_CALLBACK_2 \
#define CUSTOM_CALLBACK_2 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#elif not not defined CUSTOM_CALLBACK_3 \
#define CUSTOM_CALLBACK_3 \
FORWARD_DECLARE_CALLBACK_FUNCTION(callbackFunctName) \
#endif
为什么不使用ifndef? – Dariusz 2013-02-11 08:30:14
'#elif未定义CUSTOM_CALLBACK_3'未定义? – JustMaximumPower 2013-02-11 08:30:26
你想做什么?您不能定义包含其他预处理器指令的宏。你不能使'#define'或'#if'或'#elif'成为宏的一部分。您的宏必须重新设计,以确保它没有内部“分支”。所有宏观分支都必须在“外部”完成。它不能被“嵌入”到宏中。 – AnT 2013-02-11 08:33:47