Common macros and compiler attributes/pragmas configuration. More...
Common macros and compiler attributes/pragmas configuration.
Definition in file container.h.
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
#define | container_of(PTR, TYPE, MEMBER) ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) |
Returns the container of a pointer to a member. | |
#define | index_of(ARRAY, ELEMENT) (((uintptr_t)(ELEMENT) - (uintptr_t)(ARRAY)) / sizeof((ARRAY)[0])) |
Returns the index of a pointer to an array element. | |
#define | ARRAY_SIZE(a) (sizeof((a)) / sizeof((a)[0])) |
Calculate the number of elements in a static array. | |
#define ARRAY_SIZE | ( | a | ) | (sizeof((a)) / sizeof((a)[0])) |
Calculate the number of elements in a static array.
[in] | a | Array to examine |
Definition at line 83 of file container.h.
#define container_of | ( | PTR, | |
TYPE, | |||
MEMBER | |||
) | ((TYPE *) ((char *) (PTR) - offsetof(TYPE, MEMBER))) |
Returns the container of a pointer to a member.
For a struct TYPE
with a member MEMBER
, given a pointer PTR
to TYPE::MEMBER
this function returns a pointer to the instance of TYPE
.
E.g. for struct my_struct_t { ...; something_t n; ... } my_struct;
, &my_struct == container_of(&my_struct.n, struct my_struct_t, n)
.
[in] | PTR | pointer to a member |
[in] | TYPE | a type name (a struct or union), container of PTR |
[in] | MEMBER | name of the member of TYPE which PTR points to |
Definition at line 62 of file container.h.
#define index_of | ( | ARRAY, | |
ELEMENT | |||
) | (((uintptr_t)(ELEMENT) - (uintptr_t)(ARRAY)) / sizeof((ARRAY)[0])) |
Returns the index of a pointer to an array element.
[in] | ARRAY | an array |
[in] | ELEMENT | pointer to an array element |
Definition at line 74 of file container.h.