摘要: 1、前言 今天在看代码时,遇到offsetof和container_of两个宏,觉得很有意思,功能很强大。offsetof是用来判断结构体中成员的偏移位置,container_of宏用来根据成员的地址来获取结构体的地址。两个宏设计的很巧妙,值得学习。linux内核中有着两个宏的定义,并在链表结构中得到应用。不得不提一下linux内核中的链表,设计的如此之妙,只需要两个指针就搞定了。后续认真研究一下这个链表结构。2、offsetof宏 使用offsetof宏需要包含stddef.h头文件,实例可以参考:http://www.cplusplus.com/reference/cstddef/of.. 阅读全文
posted @ 2013-12-13 08:54 woainilsr 阅读(4448) 评论(0) 推荐(1) 编辑
摘要: http://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.htmlconstructordestructorconstructor (priority)destructor (priority)Theconstructorattribute causes the function to be called automatically before execution entersmain (). Similarly, thedestructorattribute causes the function to be called automati 阅读全文
posted @ 2013-12-13 08:51 woainilsr 阅读(566) 评论(0) 推荐(0) 编辑