lunes, 4 de junio de 2012

C++ std::min/std::max compilation issues

I just came across this issue today: http://support.microsoft.com/kb/143208

Basically, if you have code like this:

#include "windows.h"

...

int minimum = std::min(a,b);

it's going to blow up in your face.

Notice this at the bottom of that page: "This behavior is by design" . Seriously???

I solved the issue using extra parenthesis to prevent macro expansion thanks to stackoverflow:

int minimum = (std::min)(a,b);

And by the way... "windows.h" redefines lots of other stuff, beware! e.g. try to define the function DeleteFile and see what happens!

No hay comentarios:

Publicar un comentario