language: C (gcc-4.7.2)
date: 624 days 14 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#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);
}