問題描述
在 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 創建一個接近 &遠宏?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!