core: add ARRAY_SIZE macro

This commit is contained in:
Benjamin Valentin 2019-07-18 14:43:24 +02:00
parent 900fdcf783
commit fcf31724a6

View File

@ -108,6 +108,16 @@
#define UNREACHABLE() do { /* nothing */ } while (1) #define UNREACHABLE() do { /* nothing */ } while (1)
#endif #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) * @def ALIGN_OF(T)
* @brief Calculate the minimal alignment for type T. * @brief Calculate the minimal alignment for type T.