Alex Rivera | Logout

MIN and MAX in C

Asked 2010-08-09T04:49:40.183
450

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? (Compiler extensions/builtins for mainstream compilers preferred.)

Edit
Report

1 Answer

0

I know the guy said "C"... But if you have the chance, use a C++ template:

template<class T> T min(T a, T b) { return a < b ? a : b; }

Type safe, and no problems with the ++ mentioned in other comments.

answered 2013-03-14T11:23:36.597

Your Answer