summaryrefslogtreecommitdiff
path: root/built_in.h
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2013-08-02 15:10:20 +0200
committerTobias Klauser <tklauser@distanz.ch>2013-08-02 15:12:29 +0200
commit98c15cbb658f226d52108ea2cb5b3bc27bc6a977 (patch)
tree74a1e2b730676a26ebf6ff9d6487e6dfc5ef012b /built_in.h
parentc95c515fa9075443900734039cfd7f92b5ba832f (diff)
built_in: Add min_t() and max_t() macros and use them
Introduce non-typechecking versions of min_t() and max_t() and use them where a cast would be needed. The macros were taken from the Linux Kernel, release under GPL v2. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'built_in.h')
-rw-r--r--built_in.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/built_in.h b/built_in.h
index 9f70561..6f6625e 100644
--- a/built_in.h
+++ b/built_in.h
@@ -109,6 +109,15 @@ typedef uint8_t u8;
})
#endif /* max */
+#ifndef max_t
+# define max_t(type, a, b) \
+ ({ \
+ type ___max1 = (a); \
+ type ___max2 = (b); \
+ ___max1 > ___max2 ? ___max1 : ___max2; \
+ })
+#endif /* max_t */
+
#ifndef min
# define min(a, b) \
({ \
@@ -118,6 +127,15 @@ typedef uint8_t u8;
})
#endif /* min */
+#ifndef min_t
+# define min_t(type, a, b) \
+ ({ \
+ type ___min1 = (a); \
+ type ___min2 = (b); \
+ ___min1 < ___min2 ? ___min1 : ___min2; \
+ })
+#endif /* min_t */
+
#ifndef ispow2
# define ispow2(x) ({ !!((x) && !((x) & ((x) - 1))); })
#endif