From 270e219d2ea06bde27aea242e692e5696a516952 Mon Sep 17 00:00:00 2001 From: Kevin Trogant Date: Mon, 9 Mar 2026 16:02:13 +0100 Subject: [PATCH] fix: don't rely on _Alignof (c11 feature) --- rtcore.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/rtcore.h b/rtcore.h index 607f9ef..e160e5d 100644 --- a/rtcore.h +++ b/rtcore.h @@ -141,6 +141,19 @@ typedef int32_t b32; #define force_inline inline #endif +#if __STDC_VERSION__ >= 201112L + /* C11 introduces _Alignof */ + #define ALIGNOF(T) _Alignof(T) +#else + #if defined(__GNUC__) || defined(__clang__) + /* Use the compiler-specific keyword/operator */ + #define ALIGNOF(T) __alignof__(T) + #else + /* Fallback to the portable C89/C99 trick */ + #define ALIGNOF(T) offsetof(struct { char c; T member; }, member) + #endif +#endif + /* Arena allocator */ typedef struct arena { @@ -195,9 +208,9 @@ enum */ #define alloc(...) allocx(__VA_ARGS__, alloc4, alloc3, alloc2)(__VA_ARGS__) #define allocx(a, b, c, d, e, ...) e -#define alloc2(a, t) (t *)ArenaAlloc(a, isizeof(t), _Alignof(t), 1, 0) -#define alloc3(a, t, n) (t *)ArenaAlloc(a, isizeof(t), _Alignof(t), n, 0) -#define alloc4(a, t, n, f) (t *)ArenaAlloc(a, isizeof(t), _Alignof(t), n, f) +#define alloc2(a, t) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), 1, 0) +#define alloc3(a, t, n) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), n, 0) +#define alloc4(a, t, n, f) (t *)ArenaAlloc(a, isizeof(t), ALIGNOF(t), n, f) RTC_API void *ArenaAlloc(arena *a, isize size, isize align, isize n, int flags);