如何暂时禁用C / C ++中的宏扩展? [英] How do I temporarily disable a macro expansion in C/C++?
问题描述
由于某种原因,我需要临时禁用头文件中的一些宏,并且 #undef MACRONAME
将使代码编译,但它将undef现有的宏。 p>
有没有办法只是禁用它?
我应该提到你不知道宏的值,我正在寻找一个交叉编译器解决方案(至少应该在GCC和MSVC工作) 。
在MSVC中,您可以使用 push_macro
pragma,GCC 支持它与Microsoft Windows编译器的兼容性。
#pragma push_macro(MACRONAME)
#undef MACRONAME
//一些动作
#pragma pop_macro(MACRONAME)
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 macro.
Is there a way of just disabling it?
I should mention that you do not really know the values of the macros and that I'm looking for a cross compiler solution (should work at least in GCC and MSVC).
In MSVC you could use push_macro
pragma, GCC supports it for compatibility with Microsoft Windows compilers.
#pragma push_macro("MACRONAME")
#undef MACRONAME
// some actions
#pragma pop_macro("MACRONAME")
这篇关于如何暂时禁用C / C ++中的宏扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!