【问题标题】:if else define for preprocessorif else 为预处理器定义
【发布时间】:2016-11-25 10:53:08
【问题描述】:
//initial code:

#define MYDEBUG YES

#if (defined(MYDEBUG) && MYDEBUG == YES)
#define NATIVEUNITID @"unitid_debug"
#else
#define NATIVEUNITID @"unitid_release"
#endif


//somewhere inside the code

NATIVEUNITID 是@"unitid_release"

可能是我不明白的东西。但为什么?什么是正确的定义方式 NATIVEUNITID 使用其他定义?

#if (MYDEBUG) 和 #if (MYDEBUG == true) 我都试过了,但我得到了相同的结果。

请帮助我理解这个简单的案例。我怎样才能收到 NATIVEUNITID 是 @"unitid_debug" 吗?

【问题讨论】:

    标签: objective-c c-preprocessor preprocessor-directive


    【解决方案1】:

    预处理器无法为“字符串”评估 ==。

    如果你写#DEFINE YES 1,你可以保留你的符号

    【讨论】:

      【解决方案2】:

      改进this answer

      #if !defined(YES)
      #define YES (BOOL)1
      #endif
      #if !defined(NO)
      #define NO  (BOOL)0
      #endif
      

      之前

      #define MYDEBUG YES
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-26
        • 2021-10-12
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多