container_of macro
include/container_of.h View source View on GitHubMacros
Section titled “Macros”container_of
Section titled “container_of”#define container_of(ptr, type, member) source Expansion
#define container_of(ptr, type, member) \
({ \
static_assert(ci_types_compatible_p(typeof(*(ptr)), \
typeof(((type *) 0)->member)), \
"Incompatible types for container_of"); \
(type *) ((size_t) ptr - offsetof(type, member)); \
})