Global: Improve ARRAY_SIZE macro using __is_array

This commit is contained in:
李通洲
2025-04-30 14:47:37 +08:00
parent 5c546ab8e7
commit 3dd78422eb
+3 -1
View File
@@ -26,7 +26,9 @@
#include "options/general.h"
#ifdef __has_builtin
#if __has_builtin(__builtin_types_compatible_p)
#if __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