alternative way of showing max min definition

1
2
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define MIN(x,y) ((x) < (y) ? (x) : (y)) 



is another way of doing this but not having it defined above ?
Are you asking if there is a min and max defined in C++? If so, the answer is yes.

The stupid header file stdlib.h (and probably the equivalent cstdlib) defines those macros but in all lowercase. This causes conflicts with the STL-provided std::min() and std::max() functions included in the algorithm header file. Soooo, if you include cstdlib or stdlib.h and you want to use the STL functions, #undef the min and max macros after you #include cstdlib or stdlib.h, and before #including algorithm.
you mean like this ?

1
2
3
#include <cstdlib>
#undef min, max
#include <algorithm> 
Can you #undef 2 symbols in one line? If yes, then yes, like that.
The stupid header file stdlib.h (and probably the equivalent cstdlib) defines those macros but in all lowercase.
Uh... No, it doesn't. Following convention, all standard macros are in all upper case.
<windows.h> however, does define 'max' as a macro.
If you are going to use <windows.h> in your C++ programs it is a good idea to get into the habit of #including it this way:

1
2
#define NOMINMAX
#include <windows.h> 

This is how Microsoft does it.
closed account (3hM2Nwbp)
Just wondering, Duoas...is there a black book somewhere that Microsoft keeps of all of these little secrets in or is it all scattered throughout the reference. I've worked around the redefinition of min and max since I started C++. :P
Last edited on
Ah.... really? I was under the impression those macros were in cstdlib. I wonder why. Well, since I always program for Windows, I always have Windows.h, so maybe that led to my confusion.

OP: Check this out! #undef the macros, but better yet, do as Duoas explains it. Since I thought the macros belonged to cstdlib, I was recommending the #undef, but Duoas has come to the rescue with the appropriate data.
is there a black book somewhere

LOL, I don't think so. I only learned it recently myself. You just have to be familiar with how the WinAPI interfaces with your tools...

The best way is to read through the Windows API header files themselves...





Alas.
Topic archived. No new replies allowed.