[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 07:02:34PM +0100, Andreas Gruenbacher wrote:
> Borislav Deianov wrote:
> > AFAIK, linux/list.h is the recommended linked list implementation,
> > consider using that instead.
> This one also doesn't really solve the offset problem. In the
> version that I've proposed, there's no overhead if the offsets are
> equal, and it works if the offsets differ.

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; = 1; = 2; = 3;
list_add(&n1.list, &queue);
list_add(&n2.list, &queue);
list_add(&n3.list, &queue);
tmp =;
while(tmp != &queue) {
struct node *n = list_entry(tmp, struct node, list);
printf("%d\n", n->data);
tmp = tmp->next;
------------------------ </list.c> -----------------------

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    [from the cache]
©2003-2014 Jasper Spaans. hosted at Digital Ocean