nginx取结构体地址

linux内核提供了一个container_of()宏,可以根据结构体某个成员的地址找到父结构的地址。

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

而在Nginx也是效仿采用一样的宏获取父结构地址。

#define ngx_queue_data(q, type, link)   \
    (type *) ((u_char *) q - offsetof(type, link))
posted @ 2017-10-13 08:08  抟九  阅读(298)  评论(0编辑  收藏  举报