fix: don't rely on _Alignof (c11 feature)

This commit is contained in:
Kevin Trogant 2026-03-09 16:02:13 +01:00
parent cc7ef60be2
commit 270e219d2e

View File

@ -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);