Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a statement expression equivalent in Visual Studio?

GCC has a statment expression feature that allows macro to be defined as:

#define maxint(a,b) \
   ({int _a = (a), _b = (b); _a > _b ? _a : _b; })

This is illegal in Visual Studio.

Is there an equivalent feature in microsoft visual studio? (I know, I would better use GCC. But I am just curious).

Or, do we just have to resort to inline functions?

like image 974
SHH Avatar asked Nov 15 '11 20:11

SHH


2 Answers

If you were using C++, I believe a lambda function could be used:

#define maxint(a,b) \
   ([=] () {int _a = (a), _b = (b); return _a > _b ? _a : _b; }())
like image 127
Bryan Avatar answered Oct 22 '22 00:10

Bryan


There is no equivalent in the MS compiler to this non-standard GCC language extension.

like image 36
David Heffernan Avatar answered Oct 21 '22 22:10

David Heffernan