# non-uppercase max macro

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, does anyone know of any libraries/headers that define a non-UPPERCASE macro max like this: #define max(a, b) (((a) > (b)) ? (a) : (b)) ? Whoever did that, I hate him or her. It screws up std::numeric_limits::max(). I couldn't figure out what the heck the problem was until intellisense told me some wonderful person made it a macro. I have included DirectX 9 headers and libraries (including D3DX stuff) and Ogg Vorbis headers and libraries. Who did this horrible horrible deed?

##### Share on other sites
The macro is defined in WinDef.h. You can disable them by defining NOMINMAX before including any Windows headers.

[Edited by - igni ferroque on October 10, 2005 10:03:37 AM]

##### Share on other sites
Yes, I too would like the head of the person who decided that was a good idea.

##### Share on other sites
Quote:
 Original post by OxyacetyleneYes, I too would like the head of the person who decided that was a good idea.

It predates std::numeric_limits::max. I suppose we should ask for your head for blithely using namespace std, or not fully understanding namespace disambiguation?

##### Share on other sites
Quote:
 Original post by igni ferroqueThe macro is defined in WinDef.h. You can disable them by defining NOMINMAX before including any Windows headers. Alternatively, use the full name of the STL max method.

Or #undef

##### Share on other sites
Quote:
 Original post by igni ferroqueThe macro is defined in WinDef.h. You can disable them by defining NOMINMAX before including any Windows headers. Alternatively, use the full name of the STL max method.

Very nice, thanks.

Quote:
Original post by Oluseyi
Quote:
 Original post by OxyacetyleneYes, I too would like the head of the person who decided that was a good idea.

It predates std::numeric_limits::max. I suppose we should ask for your head for blithely using namespace std, or not fully understanding namespace disambiguation?

This max macro is so annoying because it's not following the convention that macros are ALL CAPS, which leads to problems like this.

##### Share on other sites
Quote:
Original post by Oluseyi
Quote:
 Original post by OxyacetyleneYes, I too would like the head of the person who decided that was a good idea.

It predates std::numeric_limits::max. I suppose we should ask for your head for blithely using namespace std, or not fully understanding namespace disambiguation?

Also, win32 is a C api, not C++. You can get away with using C++ because the nice folks who created and standardized C++ made it compatible (mostly) with C and MS has done some stuff to make thier headers C++ friendly as well. Obviously there is no such thing as std::numeric_limits:max in C.

##### Share on other sites
Quote:
Original post by Anon Mike
Quote:
Original post by Oluseyi
Quote:
 Original post by OxyacetyleneYes, I too would like the head of the person who decided that was a good idea.

It predates std::numeric_limits::max. I suppose we should ask for your head for blithely using namespace std, or not fully understanding namespace disambiguation?

Also, win32 is a C api, not C++. You can get away with using C++ because the nice folks who created and standardized C++ made it compatible (mostly) with C and MS has done some stuff to make thier headers C++ friendly as well. Obviously there is no such thing as std::numeric_limits:max in C.

I think I worded my original post unclearly. This evil "max" macro screws up std::numeric_limits::max because std::numeric_limit's max function is well, called "max". I guess the preprocessor doesn't care that there's the :: symbols preceeding this particular max, any function called max gets killed by this, not just std::numeric_limits::max. Again, if whoever wrote this had made it ALL CAPS as is convention no one would be having this problem.

##### Share on other sites
Quote:
 Original post by load_bitmap_fileAgain, if whoever wrote this had made it ALL CAPS as is convention no one would be having this problem.

Unless someone wrote a MAX function.

The real lesson is the danger of macros and preprocessor substitution: "This, kids, is why you should prefer inline functions to macros." And read documentation, since disabling the macro is both trivial and clearly anticipated by the Win32 API authors.

##### Share on other sites
Quote:
Original post by Oluseyi
Quote:
 Original post by OxyacetyleneYes, I too would like the head of the person who decided that was a good idea.

It predates std::numeric_limits::max. I suppose we should ask for your head for blithely using namespace std, or not fully understanding namespace disambiguation?

#include <windows.h>#include <iostream>#include <limits>int main(int,char**){	std::cout << std::numeric_limits<float>::max();	return(0);}

c:\Cpp\Scrap\Scrap\main.cpp(7): error C2059: syntax error : '::'
c:\Cpp\Scrap\Scrap\main.cpp(7): error C2589: '(' : illegal token on right side of '::'
c:\Cpp\Scrap\Scrap\main.cpp(7): warning C4003: not enough actual parameters for macro 'max'

This completely scoped to hell max() call will generate this error with MSVC 7.1 I've run into this before several times and its irritating as hell.

If you comment out the include of windows.h the error is no longer an issue. I've even tried including windows after the std includes but that also generates the same errors and warnings. You must actually undefine min/mix in order to properly use the std::numeric_limits functions.

[EDIT]
Should've read all posts =) I see someone already got to this point