macro: introduce PA_INT_TYPE_MIN, PA_INT_TYPE_MAX, PA_INT_TYPE_SIGNED macros
authorLennart Poettering <lennart@poettering.net>
Fri, 18 Sep 2009 02:05:54 +0000 (04:05 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 18 Sep 2009 02:14:37 +0000 (04:14 +0200)
src/pulsecore/macro.h

index bffcc26..9a5a267 100644 (file)
@@ -304,6 +304,18 @@ typedef int pa_bool_t;
 #define pa_memzero(x,l) (memset((x), 0, (l)))
 #define pa_zero(x) (pa_memzero(&(x), sizeof(x)))
 
+#define PA_INT_TYPE_SIGNED(type) (!!((type) 0 > (type) -1))
+
+#define PA_INT_TYPE_MAX(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? ~(~(type) 0 << (8*sizeof(type)-1))                      \
+             : (type) -1))
+
+#define PA_INT_TYPE_MIN(type)                                          \
+    ((type) (PA_INT_TYPE_SIGNED(type)                                  \
+             ? (~(type) 0 << (8*sizeof(type)-1))                       \
+             : (type) 0))
+
 /* We include this at the very last place */
 #include <pulsecore/log.h>