summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2014-08-22 13:55:57 +0200
committerDavid Herrmann <dh.herrmann@gmail.com>2014-08-22 14:01:05 +0200
commit40a1eebde6be7ac3f1885147fc24e06ad1da260c (patch)
treea03d9895d6577fe38480633774050f41ae5ba079 /src/shared
parent0975b63fb31263e535a2d26ed41e66e23f468bc5 (diff)
shared: add MAXSIZE() and use it in resolved
The MAXSIZE() macro takes two types and returns the size of the larger one. It is much simpler to use than MAX(sizeof(A), sizeof(B)) and also avoids any compiler-extensions, unlike CONST_MAX() and MAX() (which are needed to avoid evaluating arguments more than once). This was suggested by Daniele Nicolodi <daniele@grinta.net>. Also make resolved use this macro instead of CONST_MAX(). This enhances readability quite a bit.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/macro.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/shared/macro.h b/src/shared/macro.h
index 179b24c983..43fa3e556f 100644
--- a/src/shared/macro.h
+++ b/src/shared/macro.h
@@ -149,6 +149,9 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
((_A) > (_B)) ? (_A) : (_B), \
(void)0))
+/* takes two types and returns the size of the larger one */
+#define MAXSIZE(A, B) (sizeof(union _packed_ { typeof(A) a; typeof(B) b; }))
+
#define MAX3(x,y,z) \
__extension__ ({ \
const typeof(x) _c = MAX(x,y); \