From e822fc576a9c2210aec9fc3d947fa859c03a0f22 Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Tue, 25 Aug 2009 13:11:42 +0200 Subject: [PATCH] Added side effect free min and max macros. --- src/libstrongswan/utils.h | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/libstrongswan/utils.h b/src/libstrongswan/utils.h index 6b0990f5e..35008f455 100644 --- a/src/libstrongswan/utils.h +++ b/src/libstrongswan/utils.h @@ -72,12 +72,19 @@ /** * Macro gives back larger of two values. */ -#define max(x,y) ((x) > (y) ? (x):(y)) +#define max(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + _x > _y ? _x : _y; }) + /** * Macro gives back smaller of two values. */ -#define min(x,y) ((x) < (y) ? (x):(y)) +#define min(x,y) ({ \ + typeof(x) _x = (x); \ + typeof(y) _y = (y); \ + _x < _y ? _x : _y; }) /** * Call destructor of an object, if object != NULL