Skip to content

container_of macro

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