3 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
5 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
7 define ALIGN(x,a) __ALIGN_MASK(x,(typeof(x))(a)-1)
8 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
9 #define PTR_ALIGN(p, a) ((typeof(p))ALIGN((unsigned long)(p), (a)))
10 #define IS_ALIGNED(x, a) (((x) & ((typeof(x))(a) - 1)) == 0)
14 * container_of - cast a member of a structure out to the containing structure
15 * @ptr: the pointer to the member.
16 * @type: the type of the container struct this is embedded in.
17 * @member: the name of the member within the struct.
20 #define container_of(ptr, type, member) ({ \
21 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
22 (type *)( (char *)__mptr - offsetof(type,member) );})
24 include/linux/stddef.h
27 #ifdef __compiler_offsetof
28 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
30 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
32 #endif /* __KERNEL__ */