If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Weird interaction between <algorithm> and <winsock.h>

Okay, it's a silly example - but the above code consistently gives me error C2589: '(' : illegal token on right side of '::'. I'm building with VC8. If I don't #include <winsock.h> the code compiles correctly but it doesn't matter if I #include <winsock.h> before or after including <algorithm>

I guess it might be due to one of my #defines but I've tried the code in a very minimal program and I still get the error. Is there anyone here who could try this (preferably in VC8) and let me know if they also see the problem?

Re: Weird interaction between <algorithm> and <winsock.h>

unfortunately, Microsoft headers are polluted with their own min/max macros that conflict with the corresponding stl function templates. Just define NOMINMAX before any windows related inclusion to suppress those macro definitions ...

Re: Weird interaction between <algorithm> and <winsock.h>

Originally Posted by D_Drmmr

Because it cannot be interpreted as a macro call, so the preprocessor just leaves it alone.

to enlighten this...
the macro you're stumbling over is a define with parameters (even if the number of parameters is zero)
#define min(x,y) somethingsomething
// or even #define min() somethingsomething with zero parameters
this is different from a macro defined without parameters
#define min somethingsomething

in the std::min(0,16384) case, the macro 'min()' is a match. This will potentially be causing a different amount of arguments error C4002 or C4003, but in this case std::min has 2 parameters also. Note that macro matching logic DOES NOT depend on the number of parameters like in trying to match a function which can have overloads on different types and number of parameters (macro's are unique, you can't overload different number of parameters).

by writing (std::min)(something) the parens around std::min exclude the possibility for the macro 'min()' to match. But it would allow a macro 'min' to match.

The "trick" here works because min is defined as a macro with parameters.

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.