lkml.org 
[lkml]   [2000]   [Feb]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: 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/

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