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

前端 未结 9 1369
渐次进展
渐次进展 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:14

    #if MYVARIABLE==0 My answer must be at least 30 chars, so that should do it!

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • You can't since the preprocessor can only check for a numeric value. Your string compare is not covered by preprocessor syntax.

    0 讨论(0)
提交回复
热议问题