Common: refactors time formatting to use a shared buffer and utility macro

This commit is contained in:
李通洲
2025-08-19 09:49:43 +08:00
parent 4f88e1f26d
commit ea86273a0e
5 changed files with 34 additions and 23 deletions
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <assert.h>
#ifdef __has_builtin
#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
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) ((uint32_t) (sizeof(x) / sizeof(*(x))))
#endif