summaryrefslogtreecommitdiff
path: root/src/kernel/util.h
diff options
context:
space:
mode:
authordzwdz2021-09-21 18:11:10 +0200
committerdzwdz2021-09-21 18:11:10 +0200
commit262311a02c4bcf001d1b2a4ce496a5a83ec4f9e1 (patch)
treee2aee71abbe5aac7b51d8e902a3d154376fae5fd /src/kernel/util.h
parent2373680d99372b9e7cdecf1c8d4b0a7366eb3cfb (diff)
implement (safe) min/max macros
Diffstat (limited to 'src/kernel/util.h')
-rw-r--r--src/kernel/util.h10
1 files changed, 10 insertions, 0 deletions
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; })