最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

container_of – upcast to parent structure

工作和技术 crifan 1622浏览 0评论

in includelinuxkernel.h

container_of(ptr, type, member)

/**
* container_of – cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @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) );})

in includelinuxstddef.h

offsetof(TYPE, MEMBER)

#ifdef __compiler_offsetof
#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
#else
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
#endif

转载请注明:在路上 » container_of – upcast to parent structure

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
79 queries in 0.167 seconds, using 22.06MB memory