您的位置:首页 > 运维架构 > Linux

有时间练习下linux下的queue.h这个程序

2012-09-26 09:00 218 查看
下面是测试代码.

#include <stdio.h>

#include <stdlib.h>

#include <sys/queue.h>



struct foo {

int a, b, c;

LIST_ENTRY(foo) pointers;

};



LIST_HEAD(foo_list, foo);



int main(void)

{

LIST_HEAD(foo_list, foo) head;



LIST_INIT(&head);



struct foo *item = malloc(sizeof(struct foo));

item->a = 69;

item->b = 123;

LIST_INSERT_HEAD(&head, item, pointers);



LIST_FOREACH(item, &head, pointers)

{

printf("a = %d b = %d\n", item->a, item->b);

}



while (!LIST_EMPTY(&head))

{

item = LIST_FIRST(&head);

LIST_REMOVE(item, pointers);

free(item);

}



return (0);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐