/*a.out size with no inline funcs... 14412*/ /*a.out size with ALL inline funcs... 14412*/ /*weird, I was expecting SOME difference... probably smaller*/ #include #include typedef struct listnode_typ { struct listnode_typ* last; struct listnode_typ* next; int payload; } listnode; listnode* head_p; listnode* tail_p; inline void insert_node(current, next) listnode* current; listnode* next; { current->next = next; current->last = next->last; next->last = current; if(current->last) current->last->next = current; else head_p = current; return; } inline void remove_node(current) listnode* current; { current->next->last = current->last; if(current->last) current->last->next = current->next; else head_p = current->next; return; } inline void init_list(current) listnode* current; { head_p = current; tail_p = current; return ; } int main(void) { listnode* temp; int i; temp = (listnode*) malloc(sizeof(listnode)); memset(temp, 0, sizeof(listnode)); temp->payload=99; init_list(temp); printf("head_p->payload = %d\n", head_p->payload); /*ok insert 10 new nodes at the head...*/ for(i = 10; i>0; i--) { temp = (listnode*) malloc(sizeof(listnode)); temp->payload = i; insert_node(temp, head_p); } printf("head_p->payload = %d\n", head_p->payload); /*ok, now take them off from the end to the beginning*/ for(i=10; i>0; i--) { temp = tail_p->last; printf("Removing node #%d\n", temp->payload); remove_node(temp); free(temp); } /*just to prove that the head_p is intact and pointing at the * only remaining node...*/ printf("head_p->payload = %d\n", head_p->payload); free(tail_p); return 0; }