Jump to content
  • Advertisement
Sign in to follow this  
corrington_j

min and max functions on linux

This topic is 4888 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

Advertisement
alternatively you could define them yourself

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

Share this post


Link to post
Share on other sites
There are reasons why macros are generally considered evil:
#include <algorithm>
#include <iostream>

int main()
{
int a = 8;
int b = 9;
std::cout << std::min(a++, b) << '\n';
std::cout << std::max(++a, --b) << '\n';
a = 8;
b = 9;

#define min(a, b) (((a) < (b)) ? (a) : (b))
#define max(a, b) (((a) > (b)) ? (a) : (b))

std::cout << min(a++, b) << '\n';
std::cout << max(++a, --b) << '\n';
}


Just use the <algorithm> header.

Enigma

Share this post


Link to post
Share on other sites
I believe that min and max are defined (as macros) in Windows.h or one of the files it includes.

Because they are macros you cannot use std::min and std::max when min and max macros are defined.

If you define the symbol NOMINMAX before including windows.h the macros will not be defined, so you can then use std::max and std::min, which, being part of the standard library, are portable and available on both linux and Windows.

See this

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!