c/c++技巧总结

1、bzero()、memset()初始化结构体。

2、求结构体分量在结构体中地址偏移量

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

3、typeof关键字可以返回参数类型

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

 

posted on 2016-08-02 20:28  紫色年华  阅读(156)  评论(0编辑  收藏  举报

导航