Messages in this thread | | | Date | Tue, 22 Feb 2000 16:00:11 -0600 | From | Bill Wendling <> | Subject | Re: Improved <linux/lists.h> |
| |
Also sprach Borislav Deianov: } } The linux/list.h implementation is a bit weird at first (at least I } found it so) but is perfectly adequate and very neat once you get used } to it. Here is your example program rewritten to use linux/list.h } (modulo insertion/traversal order - easily changeable): } } ------------------------ <list.c> ------------------------ } #include <stdio.h> } #include "list.h" } } struct node { } int data; } struct list_head list; } }; } } int main(void) } { } struct list_head queue, *tmp; } struct node n1, n2, n3; } n1.data = 1; } n2.data = 2; } n3.data = 3; } } INIT_LIST_HEAD(&queue); } list_add(&n1.list, &queue); } list_add(&n2.list, &queue); } list_add(&n3.list, &queue); } tmp = queue.next; } while(tmp != &queue) { } struct node *n = list_entry(tmp, struct node, list); } printf("%d\n", n->data); } tmp = tmp->next; } } } list_del(&n2.list); } list_del(&n1.list); } list_del(&n3.list); } }
Our design team has something similar to what this looks like. One thing we had which was nice, it was a FOREACH() macro. Does the above code:
tmp = queue.next; while (tmp != &queue) { /* blah */ tmp = tmp->next; }
occur frequently enough to warrent such a beast?
-- || Bill Wendling wendling@ganymede.isdn.uiuc.edu
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |