C언어에서 this라니 묘하긴하지만.

struct A
{
   int a, b;
};
가 되어있을때, A 구조체의 b 포인터에서 A 구조체의 포인터를 거슬러 올라가서 구하는? 뭐 그런것.

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

길기도 하지 -_-;;;
A structure로 예를 들어보자면, 코드는 다음과 같이 활용될수있다.

void foo (int * b)
{
struct A * p;
p = container_of(b, struct A, b);
}

좀 복잡하긴함...^^;;

+ Recent posts