From 262311a02c4bcf001d1b2a4ce496a5a83ec4f9e1 Mon Sep 17 00:00:00 2001 From: dzwdz Date: Tue, 21 Sep 2021 18:11:10 +0200 Subject: implement (safe) min/max macros --- src/kernel/util.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/kernel/util.h') diff --git a/src/kernel/util.h b/src/kernel/util.h index b50810d..839aa49 100644 --- a/src/kernel/util.h +++ b/src/kernel/util.h @@ -8,3 +8,13 @@ void *memcpy(void *dest, const void *src, size_t n); void *memset(void *s, int c, size_t n); int memcmp(const void *s1, const void *s2, size_t n); + +// see https://gcc.gnu.org/onlinedocs/gcc/Typeof.html +#define min(a,b) ({ \ + typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a < _b ? _a : _b; }) +#define max(a,b) ({ \ + typeof (a) _a = (a); \ + typeof (b) _b = (b); \ + _a > _b ? _a : _b; }) -- cgit v1.2.3