Messages in this thread | | | From | Borislav Deianov <> | Date | Wed, 23 Feb 2000 00:19:50 +0100 | Subject | Re: Improved <linux/lists.h> |
| |
On Tue, Feb 22, 2000 at 04:00:11PM -0600, Bill Wendling wrote: > 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?
I've thought about this since I have the above (more or less) all over my code. The problem is, I could find no good way to do that macro. I ended up with something like:
#define for_each_entry(p,tmp,head,type,member) \ for (tmp = (head)->next; \ p = list_entry(tmp,type,member), tmp != (head); \ tmp = tmp->next)
struct node { int data; struct list_head list; };
struct list_head *queue, *tmp; struct node *n;
...
for_each_entry(n,tmp,queue,struct node,list) printf("%d\n", n->data);
...but I could never remember what order the fields come in. Or you can leave the list_entry call outside, but then the macro doesn't help much, just reduces the readability of the code. So no macro for me.
Regards, Borislav
- 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/
| |