From d1d8f0f369ce386878e79d56b2795397902bc221 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 29 May 2020 23:27:59 +0200 Subject: [PATCH] macro: add CONST_MIN() similar to CONST_MAX() --- src/basic/macro.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/basic/macro.h b/src/basic/macro.h index 78e4262e41..fd8772f377 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -286,6 +286,15 @@ static inline size_t GREEDY_ALLOC_ROUND_UP(size_t l) { UNIQ_T(A, aq) < UNIQ_T(B, bq) ? UNIQ_T(A, aq) : UNIQ_T(B, bq); \ }) +/* evaluates to (void) if _A or _B are not constant or of different types */ +#define CONST_MIN(_A, _B) \ + (__builtin_choose_expr( \ + __builtin_constant_p(_A) && \ + __builtin_constant_p(_B) && \ + __builtin_types_compatible_p(typeof(_A), typeof(_B)), \ + ((_A) < (_B)) ? (_A) : (_B), \ + VOID_0)) + #define MIN3(x, y, z) \ ({ \ const typeof(x) _c = MIN(x, y); \