From fcf31724a696ed560505d9da38aa1a341d2bc972 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 18 Jul 2019 14:43:24 +0200 Subject: [PATCH] core: add ARRAY_SIZE macro --- core/include/kernel_defines.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/core/include/kernel_defines.h b/core/include/kernel_defines.h index 79c71973a5..48900d7011 100644 --- a/core/include/kernel_defines.h +++ b/core/include/kernel_defines.h @@ -108,6 +108,16 @@ #define UNREACHABLE() do { /* nothing */ } while (1) #endif +/** + * @def ARRAY_SIZE(a) + * @brief Calculate the number of elements in a static array. + * @param[in] a Array to examine + * @returns The number of elements in the array a. + */ +#ifndef ARRAY_SIZE +#define ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) +#endif + /** * @def ALIGN_OF(T) * @brief Calculate the minimal alignment for type T.