Sign in to follow this  
AcidZombie24

min/max in *c*

Recommended Posts

Macros are dangerous in this situation because a or b will get evaluated twice, which would cause unexpected behavior on expressions whose evaluation has side effects (like a function) Beware.

Share this post


Link to post
Share on other sites
Quote:
Original post by AcidZombie24
What include has min and max?
I need it for a C file. Right now i have defines. But what is the proper header to include for min & max?


Did you know that you can search the include folder to find out? If you're not sure which headers are part of the standard, you can search the internet using google to find out which headers are standard and which are not.

The header file that you want is stdlib.h

Share this post


Link to post
Share on other sites
I believe these were added in C99, but they are in math.h:

double fmax(double x, double y);
float fmaxf(float x, float y);
long double fmaxl(long double x, long double y);
double fmin(double x, double y);
float fminf(float x, float y);
long double fminl(long double x, long double y);

They are in 7.12.12 of the C99 draft. I tried searching math.h with Visual Studio 2005, and came up empty. If I were a betting man, I'd say these are C99 additions.

Share this post


Link to post
Share on other sites
Quote:
Original post by thre3dee
I think <windows.h> defines them if theyre not defined.


Windows does define them, but as a C++ programmer I always #define NOMINMAX to stop the macros from treading on the STL std::min and std::max. If you're going to use macros, please use upper case naming like MIN(x,y) and MAX(x,y) so that it's obvious what they are.

Share this post


Link to post
Share on other sites
Quote:
Original post by LessBread
Quote:
Original post by AcidZombie24
What include has min and max?
I need it for a C file. Right now i have defines. But what is the proper header to include for min & max?


Did you know that you can search the include folder to find out? If you're not sure which headers are part of the standard, you can search the internet using google to find out which headers are standard and which are not.

The header file that you want is stdlib.h


I search msvc and found it in minmax.h, i search that and found it included in no headers. So i thought it might be hidden in a precompiled header or something strange like that.

I googled both stdlib and math and both did not come up with min/max

tommorow night i'll try including those headers and see if it works on all platforms.

Thanks for the reply guys

stonemetal: i think your right, i dont think it is in a standard header.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this