Re: Improved <linux/lists.h>

From: Bill Wendling (wendling@ganymede.isdn.uiuc.edu)
Date: Tue Feb 22 2000 - 17:00:11 EST


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/



This archive was generated by hypermail 2b29 : Wed Feb 23 2000 - 21:00:32 EST