use*_*918 1 c c++ macros visual-studio
我正在尝试编写一些需要在 Visual Studio 和 linux (gcc) 环境中编译/运行的代码。当我尝试在 Windows 中编译我的文件时,我遇到了一个有点模糊的错误,我想知道是否有人可以指出我缺少的内容...我有标准宏:
#define __MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
Run Code Online (Sandbox Code Playgroud)
然后当我尝试调用它时:
int x = __MAX(0, 2);
Run Code Online (Sandbox Code Playgroud)
我expected an expression在 Visual Studio 中收到错误,指向这一行。我是视觉工作室的新手,所以我不确定它不喜欢这个。谁能指出我做错了什么?
小智 5
这种类型的东西是 gcc 特定的。当使用 cl.exe(Visual Studio 使用的微软编译器)编译时,你没有这些东西。 https://social.msdn.microsoft.com/Forums/vstudio/en-US/984ae3e8-6391-45b9-8885-edb088da8bfa/will-msvc-support-a-typeof-operator-like-in-gcc?forum= vc语言