From 98c15cbb658f226d52108ea2cb5b3bc27bc6a977 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 2 Aug 2013 15:10:20 +0200 Subject: 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 --- built_in.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'built_in.h') 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 -- cgit v1.2.3-54-g00ecf