2016-11-25 97 views
-1
//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"

回答

1

預處理器無法爲==評估「字符串」。

,如果你寫#DEFINE YES 1

0

爲了提高你可以保留你的符號this answer

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

#define MYDEBUG YES