Where are MIN
and MAX
defined in C, if at all?
What is the best way to implement these, as generically and type safely as possible? (Compil
There's a std::min
and std::max
in C++, but AFAIK, there's no equivalent in the C standard library. You can define them yourself with macros like
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
But this causes problems if you write something like MAX(++a, ++b)
.