v1.1.3 - Align Arena_Region data flexible array member

This commit is contained in:
seajee
2026-01-14 18:11:15 +01:00
parent 1ffc6e1402
commit c5a38cc501
2 changed files with 11 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
// arena.h - v1.1.2 - MIT License
// arena.h - v1.1.3 - MIT License
// single header library for region-based memory management.
//
// [License and changelog]
@@ -158,7 +158,7 @@ struct Arena_Region {
Arena_Region *next;
size_t count;
size_t capacity;
uint8_t data[];
alignas(ARENA_ALIGNMENT) uint8_t data[];
};
typedef struct Arena {
@@ -335,6 +335,7 @@ char *arena_strdup(Arena *a, const char *s)
/*
* Revision history:
*
* 1.1.3 (2026-01-14) Align Arena_Region data flexible array member
* 1.1.2 (2026-01-10) Minor changes; check result of alloc in arena_copy()
* 1.1.1 (2025-11-18) Implement memory alignment; improve docs
* 1.1.0 (2025-11-18) New helper functions: arena_copy(), arena_strdup()

8
test.c
View File

@@ -25,7 +25,15 @@ void arena_print(Arena arena)
int main(void)
{
printf("struct Arena_Region {\n");
printf(" Arena_Region *next; (%zu)\n", offsetof(struct Arena_Region, next));
printf(" size_t count; (%zu)\n", offsetof(struct Arena_Region, count));
printf(" size_t capacity; (%zu)\n", offsetof(struct Arena_Region, capacity));
printf(" uint8_t data[]; (%zu)\n", offsetof(struct Arena_Region, data));
printf("};\n");
printf("Alignment: %zu\n", ARENA_ALIGNMENT);
printf("================================================================\n");
Arena a = {0};