VC++允许 /##/ 作为宏的值 - 如何在 eclipse/mingw-gcc 中处理它?

发布于 2025-01-02 14:31:10 字数 1099 浏览 0 评论 0原文

我正在尝试在 eclipse/mingw-gcc 中编译一个真正的 win32 应用程序,到目前为止还很不成功(参见 https://stackoverflow.com/ questions/9162976/how-to-compile-a-win32-application-in-eclipse-using-the-mingw-gcc-toolchain

无论如何,在排除另一个错误时,以下行在文件 c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WTypes.h 中引起了我的好奇:

#define _VARIANT_BOOL    /##/

它在 struct tagVARIANT 来自 C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\OAIdl.h

VARIANT_BOOL boolVal;
_VARIANT_BOOL bool;
SCODE scode;

扩展为:

VARIANT_BOOL boolVal;

SCODE scode;

因为 /##/被扩展为//,开始评论!我不相信它符合标准,并且确实尝试在 mingw-gcc 中编译失败:

pasting "/" and "/" does not give a valid preprocessing token   ComHelpers      line 445, external location: o:\C\wsdk\Include\oaidl.h  C/C++ Problem

因此,我正在寻找有关如何解决此问题的建议。

I am trying to compile a real win32 application in eclipse/mingw-gcc, quite unsuccessfully until now (see https://stackoverflow.com/questions/9162976/how-to-compile-a-win32-application-in-eclipse-using-the-mingw-gcc-toolchain)

Anyway, while troubleshooting yet another error, the following line in the file c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\WTypes.h has caught my curiosity:

#define _VARIANT_BOOL    /##/

It is used within the struct tagVARIANT from C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Include\OAIdl.h:

VARIANT_BOOL boolVal;
_VARIANT_BOOL bool;
SCODE scode;

which expands to:

VARIANT_BOOL boolVal;

SCODE scode;

Because /##/ is expanded to //, which starts a comment! I do not believe it is compliant to the standard and indeed trying to compile in mingw-gcc fails with:

pasting "/" and "/" does not give a valid preprocessing token   ComHelpers      line 445, external location: o:\C\wsdk\Include\oaidl.h  C/C++ Problem

So, I am looking for advices on how to solve this problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪花飘飘的天空 2025-01-09 14:31:10

您需要弄清楚宏在什么条件下具有问题定义,并在这种情况下取​​消定义它。如果没有办法判断,那就无条件取消定义它,希望没问题。 :(

#include <problem-header.h>

#if whatever condition makes sense
#undef _VARIANT_BOOL
#endif

.....

#ifdef _VARIANT_BOOL
_VARIANT_BOOL bool;
#endif

You'll need to figure out under what conditions the macro has the problem definition, and undef it in that case. If there's no way to tell, then just undef it unconditionally, and hope that's ok. :(

#include <problem-header.h>

#if whatever condition makes sense
#undef _VARIANT_BOOL
#endif

.....

#ifdef _VARIANT_BOOL
_VARIANT_BOOL bool;
#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文