diff options
author | Lennart Poettering <lennart@poettering.net> | 2020-05-29 23:27:59 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2020-06-25 15:00:09 +0200 |
commit | d1d8f0f369ce386878e79d56b2795397902bc221 (patch) | |
tree | 9123a203ed4b6b0eb791f4e96752e70bd2b08fea /src | |
parent | f49bead3b0aa826bac0d5d5d061835e5ee2813fc (diff) | |
download | systemd-d1d8f0f369ce386878e79d56b2795397902bc221.tar.gz |
macro: add CONST_MIN() similar to CONST_MAX()
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/macro.h | 9 |
1 files changed, 9 insertions, 0 deletions
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); \ |