有没有从创建一个与附近一放干净的方式prevent WINDOWS.H;远宏? [英] Is there a clean way to prevent windows.h from creating a near & far macro?

查看:136
本文介绍了有没有从创建一个与附近一放干净的方式prevent WINDOWS.H;远宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在WINDEF.H内心深处有一个从分段存储时代遗物这样:

Deep down in WinDef.h there's this relic from the segmented memory era:

#define far
#define near

这显然会导致问题,如果你试图或近或远用作变量名。任何清洁的解决方法?其他然后重命名我的变量?

This obviously causes problems if you attempt to use near or far as variable names. Any clean workarounds? Other then renaming my variables?

推荐答案

您可以安全地取消定义它们,违背他人索赔。原因是,他们只是宏的。他们不仅会影响他们的定义和他们的undefinition之间的preprocessor。在你的情况,那将是在WINDOWS.H年初WINDOWS.H的最后一行。如果你需要额外的窗口标题,你会WINDOWS.H之后和之前和#undef包含它们。在您的code时,preprocessor就干脆离开符号不变,如预期。

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.

约旧的code的注释是无关紧要的。这code将在一个单独的库,独立编制。只有在链接时将这些连接,当宏已经一去不复返了。

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.

这篇关于有没有从创建一个与附近一放干净的方式prevent WINDOWS.H;远宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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