Jump to content
  • Advertisement
Sign in to follow this  
load_bitmap_file

non-uppercase max macro

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Oxyacetylene
Yes, 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 this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by igni ferroque
The 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 this post


Link to post
Share on other sites
Quote:
Original post by igni ferroque
The 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 Oxyacetylene
Yes, 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 this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Oxyacetylene
Yes, 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 this post


Link to post
Share on other sites
Quote:
Original post by Anon Mike
Quote:
Original post by Oluseyi
Quote:
Original post by Oxyacetylene
Yes, 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 this post


Link to post
Share on other sites
Quote:
Original post by load_bitmap_file
Again, 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 this post


Link to post
Share on other sites
Quote:
Original post by Oluseyi
Quote:
Original post by Oxyacetylene
Yes, 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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!