1 #ifndef _LINUX_STDDEF_H 2 #define _LINUX_STDDEF_H 3 4 #undef NULL 5 #if defined(__cplusplus) 6 #define NULL 0 7 #else 8 #define NULL ((void *)0) 9 #endif 10 11 #undef offsetof 12 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) 13 14 15 /** 16 * container_of - cast a member of a structure out to the containing structure 17 * 18 * @ptr: the pointer to the member. 19 * @type: the type of the container struct this is embedded in. 20 * @member: the name of the member within the struct. 21 * 22 */ 23 #define container_of(ptr, type, member) ({ \ 24 const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 25 (type *)( (char *)__mptr - offsetof(type,member) );}) 26 27 /* 28 * Check at compile time that something is of a particular type. 29 * Always evaluates to 1 so you may use it easily in comparisons. 30 */ 31 #define typecheck(type,x) \ 32 ({ type __dummy; \ 33 typeof(x) __dummy2; \ 34 (void)(&__dummy == &__dummy2); \ 35 1; \ 36 }) 37 38 39 #endif 40