Replace MAX, MIN, ABS macros by type-checking variants.
[paraslash.git] / para.h
diff --git a/para.h b/para.h
index a39ed97df45502a0f93dcd8217cf5d9d6e792c78..3f2da13a859782ba8c5a014d6e6511ecd97d1f28 100644 (file)
--- a/para.h
+++ b/para.h
 /** used in various contexts */
 #define MAXLINE 255
 
-/** compute the minimum of \a a and \a b */
-#define PARA_MIN(a,b) ((a) < (b) ? (a) : (b))
-/** compute the maximum of \a a and \a b */
-#define PARA_MAX(a,b) ((a) > (b) ? (a) : (b))
-/** compute the absolute value of \a a */
-#define PARA_ABS(a) ((a) > 0 ? (a) : -(a))
+/** Compute the minimum of \a x and \a y. */
+#define PARA_MIN(x, y) ({ \
+       typeof(x) _min1 = (x); \
+       typeof(y) _min2 = (y); \
+       (void) (&_min1 == &_min2); \
+       _min1 < _min2 ? _min1 : _min2; })
+
+/** Compute the maximum of \a x and \a y. */
+#define PARA_MAX(x, y) ({ \
+       typeof(x) _max1 = (x); \
+       typeof(y) _max2 = (y); \
+       (void) (&_max1 == &_max2); \
+       _max1 < _max2 ? _max1 : _max2; })
+
+/** Compute the absolute value of \a x. */
+#define PARA_ABS(x) ({ \
+       typeof(x) _x = (x); \
+       _x > 0? _x : -_x; })
 
 /** debug loglevel, gets really noisy */
 #define DEBUG 1