From 9803fbbf7a450aadab6008d061221eaf9279d398 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sun, 30 Nov 2025 13:13:48 -0500 Subject: lib: Improve STATIC_ASSERT, add TYPES_ARE_EQUAL Signed-off-by: Andrew Opalach --- include/al/lib.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include') 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 -- cgit v1.2.3-101-g0448