diff options
Diffstat (limited to 'src/include/stddef.h')
-rw-r--r-- | src/include/stddef.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/include/stddef.h b/src/include/stddef.h index 137de04405d5..3a030e14a137 100644 --- a/src/include/stddef.h +++ b/src/include/stddef.h @@ -32,6 +32,17 @@ typedef unsigned int wint_t; offsetof(struct structure, member) == offset, \ "`struct " #structure "` offset for `" #member "` is not " #offset ) +/** + * container_of - cast a member of a structure out to the containing structure + * @param ptr: the pointer to the member. + * @param type: the type of the container struct this is embedded in. + * @param member: the name of the member within the struct. + * + */ +#define container_of(ptr, type, member) ({ \ + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) + #ifdef __PRE_RAM__ #define ROMSTAGE_CONST const #else |