How do I temporarily disable a macro expansion in C/C++?

后端 未结 5 1912
予麋鹿
予麋鹿 2020-12-08 00:54

For some reason I need to temporarily disable some macros in a header file and the #undef MACRONAME will make the code compile but it will undef the existing ma

5条回答
  •  清歌不尽
    2020-12-08 01:16

    The macros come from some header file, so you should have access to their values. You can then do something like

    #include  // declares macro FOO
    
    // Do things with FOO
    
    #undef FOO
    
    // do things without FOO
    
    #include  // reenable FOO
    

    Your header should then be designed along these lines

    #ifndef FOO
    #define FOO do_something(x,y)
    #endif
    

提交回复
热议问题