Visual C 中宏中的可变长度参数++

发布于 2025-01-18 09:33:01 字数 434 浏览 4 评论 0原文

经过多年主要使用 gcc 后,我突然需要在 Windows 上使用 Visual C++。我需要翻译的最新内容是:

#ifdef DBG_ENABLE
#define DBG_PRINT(x...)  printf(x)
#else
#define DBG_PRINT(x...)
#endif

这给了我这个错误:

error C2010: '.': unexpected in macro parameter list

有人可以分享 Windows 的方法吗?

我尝试用谷歌搜索并搜索 Microsoft 文档,但无法找到一种方法来表达带来相关结果的问题。

After years of mostly using gcc, I suddenly have a need to use Visual C++ on Windows. The latest thing I need to translate is this:

#ifdef DBG_ENABLE
#define DBG_PRINT(x...)  printf(x)
#else
#define DBG_PRINT(x...)
#endif

Which gives me this error:

error C2010: '.': unexpected in macro parameter list

Can someone please share the Windows way of doing this?

I tried googling and searching the Microsoft docs, but couldn't figure out a way to phrase the question that brought relevant results.

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

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

发布评论

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

评论(1

难如初 2025-01-25 09:33:01

#define DBG_PRINT(x...) printf(x) 不是在 VC++ 中使用可变参数宏的正确语法。

根据有关可变参数宏的 Microsoft 文档,请尝试以下操作:

#ifdef DBG_ENABLE
#define DBG_PRINT(...) printf(__VA_ARGS__)
#else
#define DBG_PRINT(...)
#endif

或者:

#ifdef DBG_ENABLE
#define DBG_PRINT(s, ...) printf(s, __VA_ARGS__)
#else
#define DBG_PRINT(s, ...)
#endif

#define DBG_PRINT(x...) printf(x) is not the correct syntax for using variadic macros in VC++.

Per Microsoft documentation on Variadic macros, try this instead:

#ifdef DBG_ENABLE
#define DBG_PRINT(...) printf(__VA_ARGS__)
#else
#define DBG_PRINT(...)
#endif

Or:

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