Added side effect free min and max macros.

This commit is contained in:
Tobias Brunner
2009-09-01 12:50:50 +02:00
parent 8f68b72424
commit e822fc576a
+9 -2
View File
@@ -72,12 +72,19 @@
/** /**
* Macro gives back larger of two values. * 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. * 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 * Call destructor of an object, if object != NULL