[lkml]   [2000]   [Feb]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
SubjectRe: 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 =;
> 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.


To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

 \ /
  Last update: 2005-03-22 13:56    [W:0.131 / U:4.728 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site