ns2
//
//
#define LIST_HEAD(name, type)
struct name {
type *lh_first;
}
//
#define LIST_ENTRY(type)
struct {
type *le_next;
type **le_prev;
// le_next
}
//
#define LIST_INIT(head) {
(head)->lh_first = NULL;
}
//
#define LIST_INSERT_AFTER(listelm, elm, field) {
if (((elm)->field.le_next = (listelm)->field.le_next) != NULL)
(listelm)->field.le_next->field.le_prev =
&(elm)->field.le_next;
(listelm)->field.le_next = (elm);
(elm)->field.le_prev = &(listelm)->field.le_next;
}
//
#define LIST_INSERT_BEFORE(listelm, elm, field) {
(elm)->field.le_prev = (listelm)->field.le_prev;
(elm)->field.le_next = (listelm);
*(listelm)->field.le_prev = (elm);
(listelm)->field.le_prev = &(elm)->field.le_next;
}
//
#define LIST_INSERT_HEAD(head, elm, field) {
if (((elm)->field.le_next = (head)->lh_first) != NULL)
(head)->lh_first->field.le_prev = &(elm)->field.le_next;
(head)->lh_first = (elm);
(elm)->field.le_prev = &(head)->lh_first; //
}
//
#define LIST_REMOVE(elm, field) {
if ((elm)->field.le_next != NULL)
(elm)->field.le_next->field.le_prev =
(elm)->field.le_prev;
*(elm)->field.le_prev = (elm)->field.le_next;
}
转自CSDN:http://blog.csdn.net/piyajee/article/details/5903382