// ----------------- // Testing Code // ----------------- #include #include #include #include "./kernel_list.h" struct Person { char *name; int age; // Allows us to have a list of struct Person struct list_head list; }; int main(int argc, char **argv) { char *n1 = "Leonardo"; char *n2 = "Michelangelo"; struct Person p1; struct Person p2; struct list_head *head; struct Person *p; p1.name = calloc(10, sizeof(char)); p2.name = calloc(10, sizeof(char)); strncpy(p1.name, n1, strlen(n1)); strncpy(p2.name, n2, strlen(n2)); INIT_LIST_HEAD(&p1.list); list_add(&p2.list, &p1.list); // get pointer to list head = &p1.list; // retrieve outside struct p = container_of(head, struct Person, list); printf("%p\n", &p1); printf("%p\n", p); free(p1.name); free(p2.name); return 0; }