1/* @title: container_of macro */
2#pragma once
3#include <compiler/core.h>
4#include <compiler/intrinsic.h>
5#define container_of(ptr, type, member) \
6 ({ \
7 static_assert(ci_types_compatible_p(typeof(*(ptr)), \
8 typeof(((type *) 0)->member)), \
9 "Incompatible types for container_of"); \
10 (type *) ((size_t) ptr - offsetof(type, member)); \
11 })
12