From: Andrew Cooper Date: Mon, 16 Mar 2015 13:29:49 +0000 (+0000) Subject: tools/libxl: Introduce min and max macros X-Git-Tag: 4.6.0-rc1~970 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=7057feebe117c64708aab054c5055e7a93341a0b;p=xen.git tools/libxl: Introduce min and max macros This is the same set used by libxc. Signed-off-by: Andrew Cooper Acked-by: Ian Campbell CC: Ian Campbell CC: Ian Jackson CC: Wei Liu --- diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 934465a87b..fcbec7f586 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -108,6 +108,22 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0])) +#define min(X, Y) ({ \ + const typeof (X) _x = (X); \ + const typeof (Y) _y = (Y); \ + (void) (&_x == &_y); \ + (_x < _y) ? _x : _y; }) +#define max(X, Y) ({ \ + const typeof (X) _x = (X); \ + const typeof (Y) _y = (Y); \ + (void) (&_x == &_y); \ + (_x > _y) ? _x : _y; }) + +#define min_t(type, x, y) \ + ({ const type _x = (x); const type _y = (y); _x < _y ? _x: _y; }) +#define max_t(type, x, y) \ + ({ const type _x = (x); const type _y = (y); _x > _y ? _x: _y; }) + #define LIBXL__LOGGING_ENABLED #ifdef LIBXL__LOGGING_ENABLED