summaryrefslogtreecommitdiff
path: root/include/al
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-11-30 13:13:48 -0500
committerAndrew Opalach <andrew@akon.city> 2025-11-30 13:13:48 -0500
commit9803fbbf7a450aadab6008d061221eaf9279d398 (patch)
treebd2a608d7fcaef57a081aa7f9d3cefbd14e50fdb /include/al
parentc54cfde860f3449d37d19255f399b216f00a871c (diff)
downloadlibalabaster-9803fbbf7a450aadab6008d061221eaf9279d398.tar.gz
libalabaster-9803fbbf7a450aadab6008d061221eaf9279d398.tar.bz2
libalabaster-9803fbbf7a450aadab6008d061221eaf9279d398.zip
lib: Improve STATIC_ASSERT, add TYPES_ARE_EQUAL
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'include/al')
-rw-r--r--include/al/lib.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/include/al/lib.h b/include/al/lib.h
index 9aff075..3195e7b 100644
--- a/include/al/lib.h
+++ b/include/al/lib.h
@@ -17,8 +17,14 @@
#define AL_ASSERT_TYPE_SIZE(type, size) \
typedef char type##__size_assert[(!!(sizeof(type) == size)) * 2 - 1]
-#define AL_STATIC_ASSERT(what, a, cmp, b) \
- typedef char what##__assert[(!!(a cmp b)) * 2 - 1]
+#define AL_EXPAND_CMP(a, cmp, b) a cmp b
+#define AL_STATIC_ASSERT(what, ...) \
+ typedef char what##__assert[(!!(AL_EXPAND_CMP(__VA_ARGS__))) * 2 - 1]
+
+#define AL_IS_SIGNED(type) (((type)(-1)) < 0)
+#define AL_TYPES_ARE_EQUAL(t1, t2) \
+ AL_STATIC_ASSERT(t1_size_eq_t2, sizeof(t1), ==, sizeof(t2)); \
+ AL_STATIC_ASSERT(t1_signedness_eq_t2, AL_IS_SIGNED(t1), ==, AL_IS_SIGNED(t2))
#define AL_USE_STDLIB
//#define AL_PARANOID_REALLOC