master ohmu/fastfetch-openbsd / src / common / arrutil.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#include <assert.h>
 4
 5#ifdef __has_builtin
 6    #if !__cplusplus && FF_SUPPORTS_COUNT_OF
 7        #define ARRAY_SIZE(x) _Countof(x)
 8    #elif __has_builtin(__is_array)
 9        #define ARRAY_SIZE(x) ({ static_assert(__is_array(typeof(x)), "Must be an array"); (uint32_t) (sizeof(x) / sizeof(*(x))); })
10    #elif __has_builtin(__builtin_types_compatible_p)
11        #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))); })
12    #endif
13#endif
14#ifndef ARRAY_SIZE
15    #define ARRAY_SIZE(x) ((uint32_t) (sizeof(x) / sizeof(*(x))))
16#endif