From 40a1eebde6be7ac3f1885147fc24e06ad1da260c Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Fri, 22 Aug 2014 13:55:57 +0200 Subject: 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 . Also make resolved use this macro instead of CONST_MAX(). This enhances readability quite a bit. --- src/test/test-util.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/test/test-util.c') diff --git a/src/test/test-util.c b/src/test/test-util.c index ac1afce86..34d5f2ed7 100644 --- a/src/test/test-util.c +++ b/src/test/test-util.c @@ -90,6 +90,10 @@ static void test_max(void) { assert_se(val1.a == 100); assert_se(MAX(++d, 0) == 1); assert_se(d == 1); + + assert_cc(MAXSIZE(char[3], uint16_t) == 3); + assert_cc(MAXSIZE(char[3], uint32_t) == 4); + assert_cc(MAXSIZE(char, long) == sizeof(long)); } static void test_first_word(void) { -- cgit v1.2.3