From: Karel Zak Date: Fri, 12 Feb 2010 20:42:46 +0000 (+0100) Subject: include: add min/max macros X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a3e5ea3047b85b73142df4bd8c76ff14ca61b459;p=util-linux include: add min/max macros Signed-off-by: Karel Zak --- diff --git a/include/c.h b/include/c.h index 413366b2..6615f6fe 100644 --- a/include/c.h +++ b/include/c.h @@ -46,4 +46,17 @@ # define FALSE 0 #endif + +#define min(x, y) ({ \ + typeof(x) _min1 = (x); \ + typeof(y) _min2 = (y); \ + (void) (&_min1 == &_min2); \ + _min1 < _min2 ? _min1 : _min2; }) + +#define max(x, y) ({ \ + typeof(x) _max1 = (x); \ + typeof(y) _max2 = (y); \ + (void) (&_max1 == &_max2); \ + _max1 > _max2 ? _max1 : _max2; }) + #endif /* UTIL_LINUX_C_H */