How do I temporarily disable a macro expansion in C/C++?(如何暂时禁用 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++ 中的宏扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何暂时禁用 C/C++ 中的宏扩展?
基础教程推荐
- 将不可复制的闭包对象传递给 std::function 参数 2021-01-01
- 如何在 C++ 中正确使用命名空间? 2022-01-01
- 如何更改 SysDateTimePick32 或 CDateTimeCtrl 的背景颜色? 2022-01-01
- 随机插入/删除的综合向量与链表基准 2022-01-01
- C++:获取传递给函数的多维数组的行大小 2021-01-01
- 如何部分禁用 cmake C/C++ 自定义编译器检查 2021-01-01
- c++ STL设置差异 2022-01-01
- 与 CAS 的原子交换(使用 gcc 同步内置函数) 2022-01-01
- 为什么我们不能使用“虚拟继承"?在 COM 中? 2022-01-01
- 提升 ASIO 流缓冲 2021-01-01
