有没有一种干净的方法来防止 windows.h 创建一个接近 &远宏?
在 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.
相关文章