如何暂时禁用 C/C++ 中的宏扩展? [英] How do I temporarily disable a macro expansion in C/C++?

查看:30
本文介绍了如何暂时禁用 C/C++ 中的宏扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我需要暂时禁用头文件中的一些宏,#undef 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.

有没有办法禁用它?

我应该提到您并不真正了解宏的值,而且我正在寻找交叉编译器解决方案(至少应该在 GCC 和 MSVC 中工作).

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).

推荐答案

在 MSVC 中,您可以使用 push_macro pragma, GCC 支持它与 Microsoft Windows 编译器的兼容性.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆