*参照元 [#j0c13b2c]
#backlinks

*説明 [#yd8af7ae]
-パス: [[linux-2.6.25/include/linux/kernel.h]]

-ポインタが指す構造体のメンバ、それを含む構造体へのポインタを返す。
--例えば、
 struct example {
    int mem_a;
    char mem_b;
 };
 struct example hoge;
 という構造体があったとする。
 
 int *ptr = &hoge.a;
 
 上記のような、構造体のメンバへのポインタしか分からない状態から
 hoge へのポインタを得たいときに container_of を使う。
 
 struct example *ptr = container_of(ptr, struct example, mem_a);
 
 すると ptr が指す先(hoge.mem_a)を含む構造体への
 ポインタ(&hoge)が得られる。


**引数 [#k503964a]
-ptr
--
-type
--指定したポインタが指すメンバを含む構造体名を指定する。
マクロが返すのは構造体へのポインタである。
-member
--ptr に指定したポインタが指すメンバ名を指定する。

**返り値 [#i54f1798]
-type *
--

**参考 [#f34cf27c]


*実装 [#r404238c]
 /**
  * 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) );})
-
--


*コメント [#xe7df4f5]
#comment

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS