aboutsummaryrefslogtreecommitdiffstats
path: root/Macros.h
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
committerDaniel Lange <DLange@git.local>2020-12-07 10:26:01 +0100
commit65357c8c46154de4e4eca14075bfe5523bb5fc14 (patch)
tree8f430ee5a0d5de377c4e7c94e47842a27c70d7e8 /Macros.h
parentf80394a20254938142011855f2954b3f63fe5909 (diff)
downloaddebian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.gz
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.tar.bz2
debian_htop-65357c8c46154de4e4eca14075bfe5523bb5fc14.zip
New upstream version 3.0.3upstream/3.0.3
Diffstat (limited to 'Macros.h')
-rw-r--r--Macros.h52
1 files changed, 49 insertions, 3 deletions
diff --git a/Macros.h b/Macros.h
index cb84b29..64aaefa 100644
--- a/Macros.h
+++ b/Macros.h
@@ -1,16 +1,62 @@
#ifndef HEADER_Macros
#define HEADER_Macros
+#include <assert.h> // IWYU pragma: keep
+
#ifndef MINIMUM
-#define MINIMUM(a, b) ((a) < (b) ? (a) : (b))
+#define MINIMUM(a, b) ((a) < (b) ? (a) : (b))
#endif
#ifndef MAXIMUM
-#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b))
+#define MAXIMUM(a, b) ((a) > (b) ? (a) : (b))
#endif
#ifndef CLAMP
-#define CLAMP(x, low, high) (((x) > (high)) ? (high) : MAXIMUM(x, low))
+#define CLAMP(x, low, high) (assert((low) <= (high)), ((x) > (high)) ? (high) : MAXIMUM(x, low))
+#endif
+
+#ifndef ARRAYSIZE
+#define ARRAYSIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#ifndef SPACESHIP_NUMBER
+#define SPACESHIP_NUMBER(a, b) (((a) > (b)) - ((a) < (b)))
+#endif
+
+#ifndef SPACESHIP_NULLSTR
+#define SPACESHIP_NULLSTR(a, b) strcmp((a) ? (a) : "", (b) ? (b) : "")
+#endif
+
+#ifdef __GNUC__ // defined by GCC and Clang
+
+#define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check)))
+#define ATTR_NONNULL __attribute__((nonnull))
+#define ATTR_NORETURN __attribute__((noreturn))
+#define ATTR_UNUSED __attribute__((unused))
+
+#else /* __GNUC__ */
+
+#define ATTR_FORMAT(type, index, check)
+#define ATTR_NONNULL
+#define ATTR_NORETURN
+#define ATTR_UNUSED
+
+#endif /* __GNUC__ */
+
+// ignore casts discarding const specifier, e.g.
+// const char [] -> char * / void *
+// const char *[2]' -> char *const *
+#ifdef __clang__
+#define IGNORE_WCASTQUAL_BEGIN _Pragma("clang diagnostic push") \
+ _Pragma("clang diagnostic ignored \"-Wcast-qual\"")
+#define IGNORE_WCASTQUAL_END _Pragma("clang diagnostic pop")
+#elif defined(__GNUC__)
+#define IGNORE_WCASTQUAL_BEGIN _Pragma("GCC diagnostic push") \
+ _Pragma("GCC diagnostic ignored \"-Wcast-qual\"")
+#define IGNORE_WCASTQUAL_END _Pragma("GCC diagnostic pop")
+#else
+#define IGNORE_WCASTQUAL_BEGIN
+#define IGNORE_WCASTQUAL_END
#endif
#endif

© 2014-2024 Faster IT GmbH | imprint | privacy policy