summaryrefslogtreecommitdiffstats
path: root/src/common/arrutil.h
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/common/arrutil.h
Add the files
Diffstat (limited to 'src/common/arrutil.h')
-rw-r--r--src/common/arrutil.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/common/arrutil.h b/src/common/arrutil.h
new file mode 100644
index 0000000..83a49d6
--- /dev/null
+++ b/src/common/arrutil.h
@@ -0,0 +1,16 @@
+#pragma once
+
+#include <assert.h>
+
+#ifdef __has_builtin
+ #if !__cplusplus && FF_SUPPORTS_COUNT_OF
+ #define ARRAY_SIZE(x) _Countof(x)
+ #elif __has_builtin(__is_array)
+ #define ARRAY_SIZE(x) ({ static_assert(__is_array(__typeof__(x)), "Must be an array"); (uint32_t) (sizeof(x) / sizeof(*(x))); })
+ #elif __has_builtin(__builtin_types_compatible_p)
+ #define ARRAY_SIZE(x) ({ static_assert(!__builtin_types_compatible_p(__typeof__(x), __typeof__(&*(x))), "Must not be a pointer"); (uint32_t) (sizeof(x) / sizeof(*(x))); })
+ #endif
+#endif
+#ifndef ARRAY_SIZE
+ #define ARRAY_SIZE(x) ((uint32_t) (sizeof(x) / sizeof(*(x))))
+#endif