Reputation: 584
I'm trying to write some code that needs to compile/run in both visual studio and linux (gcc) environment. When I try to compile my file in windows I'm getting a somewhat ambiguous error, and I'm wondering if anyone can point me to what I'm missing... I have the standard macro:
#define __MAX(a,b) \
({ __typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; })
And then when I try to invoke it:
int x = __MAX(0, 2);
I get an expected an expression
error in visual studio, pointing to this line. I'm new to visual studio, so I'm not sure what it's not liking about this. Can anyone point me to what I'm doing wrong?
Upvotes: 1
Views: 2233
Reputation: 18827
If the problem is that std::max
and std::min
don't work, because of macros, you can locally disable them, like so:
#define DONT_EXPAND_MACRO
template<template T>
const T mini(const T& a, const T& b)
{
using std::min;
return min DONT_EXPAND_MACRO (a, b);
}
Upvotes: 0
Reputation: 1
That typeof stuff is gcc specific. You don't have that stuff when compiling with cl.exe (microsoft's compiler that visual studio uses). https://social.msdn.microsoft.com/Forums/vstudio/en-US/984ae3e8-6391-45b9-8885-edb088da8bfa/will-msvc-support-a-typeof-operator-like-in-gcc?forum=vclanguage
Upvotes: 5