How to add a 'or' condition in #ifdef

前端 未结 3 1265
情话喂你
情话喂你 2020-12-22 21:15

How can I add a \'or\' condition in #ifdef ?

I have tried:

#ifdef CONDITION1 || CONDITION2

#endif
3条回答
  •  庸人自扰
    2020-12-22 22:18

    I am really OCD about maintaining strict column limits, and not a fan of "\" line continuation because you can't put a comment after it, so here is my method.

    //|¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯|//
    #ifdef  CONDITION_01             //|       |//
    #define             TEMP_MACRO   //|       |//
    #endif                           //|       |//
    #ifdef  CONDITION_02             //|       |//
    #define             TEMP_MACRO   //|       |//
    #endif                           //|       |//
    #ifdef  CONDITION_03             //|       |//
    #define             TEMP_MACRO   //|       |//
    #endif                           //|       |//
    #ifdef              TEMP_MACRO   //|       |//
    //|-  --  --  --  --  --  --  --  --  --  -|//
    
    printf("[IF_CONDITION:(1|2|3)]\n");
    
    //|-  --  --  --  --  --  --  --  --  --  -|//
    #endif                           //|       |//
    #undef              TEMP_MACRO   //|       |//
    //|________________________________________|//
    

提交回复
热议问题