├── README.md ├── .gitignore ├── main.c ├── Makefile ├── ll.c └── ll.h /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | a.out 2 | *.o 3 | ll -------------------------------------------------------------------------------- /main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | struct list_int *ll = new_list_int(10); 6 | print_addrs(ll); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | 3 | all: ll 4 | 5 | ll: main.o ll.o 6 | gcc -o ll -Wall main.o ll.o 7 | 8 | main.o: main.c ll.h 9 | gcc -I. -Wall -c main.c ll.c 10 | 11 | ll.o: ll.c ll.h 12 | gcc -I. -Wall -c ll.c 13 | 14 | clean: 15 | rm -rf *.o *.h.gch a.out ll 16 | -------------------------------------------------------------------------------- /ll.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void print_addrs(struct list_int *head) { 6 | printf("%p: head\n", head); 7 | printf("%p: head->list->next\n", &((head->list).next)); 8 | printf("%p: head->list->prev\n", &((head->list).prev)); 9 | printf("%p: head->value\n", &(head->value)); 10 | } 11 | 12 | struct list_int * new_list_int(int value) { 13 | struct list_int *p = (struct list_int *) malloc(sizeof(struct list_int)); 14 | p->value = value; 15 | return p; 16 | } -------------------------------------------------------------------------------- /ll.h: -------------------------------------------------------------------------------- 1 | // this strcuture partially defines a node of a linked list 2 | // it only holds the pointers to the next and the previous 3 | // pointers of the linked list. 4 | struct list_head { 5 | struct list_head *next; // pointer to the node next to the current one 6 | struct list_head *prev; // pointer to the node rprevious to the current one 7 | }; 8 | 9 | struct list_int { 10 | struct list_head list; // common next and prev pointers 11 | int value; // specific member as per implementation 12 | }; 13 | 14 | struct list_str { 15 | struct list_head list; // common next and prev pointers 16 | char * str; // specific member as per implementation 17 | }; 18 | 19 | void print_addrs(struct list_int *); 20 | struct list_int * new_list_int(int); 21 | --------------------------------------------------------------------------------