struct linked int data struct linked prev struct

  • Slides: 9
Download presentation
보통 자료구조의 연결 리스트 struct linked { int data; struct linked* prev; struct linked*

보통 자료구조의 연결 리스트 struct linked { int data; struct linked* prev; struct linked* next; };

간단한 예 struct list_head { struct list_head *next, *prev; } struct item { int

간단한 예 struct list_head { struct list_head *next, *prev; } struct item { int number 1; int number 2; struct list_head list; };

list. next? struct list_head { struct list_head *next, *prev; } struct item { int

list. next? struct list_head { struct list_head *next, *prev; } struct item { int number; struct list_head list; }; struct item s 1, s 2, s 3; s 2 = s 1. list. next; ? ? No No No. . !! s 2. list = s 1. list. next; 그렇다면 s 2 값은 어떻게 얻지요? ?

#define offsetof ( , ) • 어떻게 item 구조체의 특정 멤버를 통해서 자신이 속한

#define offsetof ( , ) • 어떻게 item 구조체의 특정 멤버를 통해서 자신이 속한 item 구조체를 통째로 얻지? <stddef. h> #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE*)0)->MEMBER) struct item { int number 1; int number 2; struct list_head list; }; int offset; offset = offsetof ( struct item, number 2 ); // offset = 4; 구조체의 특정 멤버와 구조체 간의 거리를 알아낼 수 있다.

list_entry = container_of struct item* item 2 = list_entry ( item 1 ->list. next,

list_entry = container_of struct item* item 2 = list_entry ( item 1 ->list. next, struct item, list ); struct item { int number 1; int number 2; struct list_head list; };

list_for_each

list_for_each