First bad bad pass.
[cascardo/kernel/notes/.git] / 03.types / 1.conv / text
1 include/linux/kernel.h
2
3 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
4
5 #define FIELD_SIZEOF(t, f) (sizeof(((t*)0)->f))
6
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)
11
12
13 /**
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.
18  *
19  */
20 #define container_of(ptr, type, member) ({                      \
21         const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
22         (type *)( (char *)__mptr - offsetof(type,member) );})
23
24 include/linux/stddef.h
25
26 #undef offsetof
27 #ifdef __compiler_offsetof
28 #define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
29 #else
30 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
31 #endif
32 #endif /* __KERNEL__ */