Is there a clean way to prevent windows.h from creating a near amp; far macro?(有没有一种干净的方法来防止 windows.h 创建一个接近 amp;远宏?)
问题描述
在 WinDef.h 的深处有一个来自分段内存时代的遗物:
Deep down in WinDef.h there's this relic from the segmented memory era:
#define far
#define near
如果您尝试使用near 或far 作为变量名,这显然会导致问题.任何干净的解决方法?其他然后重命名我的变量?
This obviously causes problems if you attempt to use near or far as variable names. Any clean workarounds? Other then renaming my variables?
推荐答案
您可以安全地取消定义它们,这与其他人的声明相反.原因是它们只是宏的.它们只影响定义和未定义之间的预处理器.在您的情况下,这将从 windows.h 的早期到 windows.h 的最后一行.如果您需要额外的窗口标题,您可以将它们包含在 windows.h 之后和 #undef 之前.在您的代码中,预处理器将按照预期简单地保持符号不变.
You can safely undefine them, contrary to claims from others. The reason is that they're just macros's. They only affect the preprocessor between their definition and their undefinition. In your case, that will be from early in windows.h to the last line of windows.h. If you need extra windows headers, you'd include them after windows.h and before the #undef. In your code, the preprocessor will simply leave the symbols unchanged, as intended.
关于旧代码的注释是无关紧要的.该代码将在一个单独的库中,独立编译.只有在链接时才会连接这些宏,而宏早已不复存在.
The comment about older code is irrelevant. That code will be in a separate library, compiled independently. Only at link time will these be connected, when macros are long gone.
这篇关于有没有一种干净的方法来防止 windows.h 创建一个接近 &远宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:有没有一种干净的方法来防止 windows.h 创建一个接


基础教程推荐
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- 这个宏可以转换成函数吗? 2022-01-01
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 常量变量在标题中不起作用 2021-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 我有静态或动态 boost 库吗? 2021-01-01