Skip to content

container_of macro

include/container_of.h View source View on GitHub
#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)); \
    })