1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:32:45 +01:00

core/include/kernel_defines.h: add index_of() macro

This commit is contained in:
Benjamin Valentin 2021-11-05 15:27:51 +01:00
parent 2947a8c669
commit 01a49d3d19

View File

@ -63,6 +63,16 @@ extern "C" {
((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER)))
#endif
/**
* @def index_of(ARRAY, ELEMENT)
* @brief Returns the index of a pointer to an array element.
* @param[in] ARRAY an array
* @param[in] ELEMENT pointer to an array element
* @return Index of the element in the array
*/
#define index_of(ARRAY, ELEMENT) (((uintptr_t)(ELEMENT) - (uintptr_t)(ARRAY)) / sizeof(*(ELEMENT)))
/**
* @def NORETURN
* @brief The *NORETURN* keyword tells the compiler to assume that the function