- #include <sys/types.h>
- #include <sys/queue.h>
- #include <unistd.h>
- struct test{
- int a;
- SLIST_ENTRY(test) next;
- };
- static SLIST_HEAD(,test) test_head;
- int main()
- {
- struct test *p = malloc(sizeof(struct test));
- p->a = 222;
- SLIST_INSERT_HEAD(&test_head,p,next);
- SLIST_FOREACH(p,&test_head,next)
- {
- printf("%d\\n",p->a);
- }
- while (!SLIST_EMPTY(&test_head)) { /* List Deletion. */
- p = SLIST_FIRST(&test_head);
- SLIST_REMOVE_HEAD(&test_head, next);
- free(p);
- }
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/170920135953.html
来源: http://www.codesnippet.cn/detail/170920135953.html