【发布时间】:2013-02-11 08:28:23
【问题描述】:
是否有一个预处理指令来检查一个常量是否没有定义。我知道#ifndef 指令,但我也在寻找#elif not defined 指令。 #elif not defined 存在吗?
这就是我将如何使用它:
#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
【问题讨论】:
-
#elif not not defined CUSTOM_CALLBACK_3未定义? -
你想做什么?您不能定义包含其他预处理器指令的宏。您不能将
#define或#if或#elif作为宏的一部分。您的宏必须重新设计以确保它没有内部“分支”。所有宏分支都必须“在外部”完成。它不能“嵌入”到宏中。
标签: c-preprocessor preprocessor-directive