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) \
({ \
static_assert(__builtin_types_compatible_p( \
typeof(*(ptr)), typeof(((type *) 0)->member)), \
"Incompatible types for containerof"); \
(type *) ((size_t) ptr - offsetof(type, member)); \
})