最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

container_of – upcast to parent structure

工作和技术 crifan 641浏览 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,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
56 queries in 0.142 seconds, using 18.83MB memory