#define container_of(ptr, type, member) ({             /
         const typeof( ((type *)0)->member ) *__mptr = (ptr);     /
         (type *)( (char *)__mptr - offsetof(type,member) );})

 

  #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)

 

注意((type *)0)的使用。比如:((void *)0)();

((TYPE *)0)->MEMBER;--->这是指MEMBER在结构体TYPE中的偏移。

相关文章:

  • 2021-12-23
  • 2021-09-05
  • 2022-12-23
  • 2021-12-14
  • 2021-12-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-09
  • 2022-12-23
  • 2022-12-23
  • 2021-07-14
  • 2022-12-23
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案