How to test if preprocessor symbol is #define'd but has no value?

前端 未结 9 1376
渐次进展
渐次进展 2020-11-30 06:08

Using C++ preprocessor directives, is it possible to test if a preprocessor symbol has been defined but has no value? Something like that:

#define MYVARIABLE         


        
9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-30 07:15

    I haven't seen this solution to the problem but am surprised it is not in common use . It seems to work in Xcode Objc. Distinguish between "defined with no value" and "defined set 0"

    #define TRACE
    #if defined(TRACE) && (7-TRACE-7 == 14)
    #error TRACE is defined with no value
    #endif
    

提交回复
热议问题