How to compare strings in C conditional preprocessor-directives

Posted in :

想使用 #define 寫code 在 preprocessor 裡,會顯示錯誤:

Invalid token at start of preprocessor expression

解法:

https://stackoverflow.com/questions/2335888/how-to-compare-strings-in-c-conditional-preprocessor-directives


解法 1,換成流水號:

#define USER_JACK 1
#define USER_QUEEN 2

#define USER USER_JACK 

#if USER == USER_JACK
#define USER_VS USER_QUEEN
#elif USER == USER_QUEEN
#define USER_VS USER_JACK
#endif

Or you could refactor the code a little and use C code instead.


解法 2:

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *