Obsolete
/
libipc-old
Archived
3
0
Fork 0
This repository has been archived on 2024-06-18. You can view files and clone it, but cannot push or open issues/pull-requests.
libipc-old/drop/list.c

57 lines
1.2 KiB
C
Raw Normal View History

2016-06-05 19:06:28 +02:00
#include <stdio.h>
#include <stdlib.h>
#include "../lib/queue.h"
// create the head of the list
LIST_HEAD(mlist, node);
// elements structure of the list
struct node {
2018-11-02 21:03:54 +01:00
int32_t content;
2016-06-05 19:06:28 +02:00
LIST_ENTRY(node) entries;
};
2018-11-02 21:03:54 +01:00
int32_t main(int32_t argc, char * argv[])
2016-06-05 19:06:28 +02:00
{
2016-09-15 23:08:08 +02:00
(void) argc;
(void) argv;
2016-06-05 19:06:28 +02:00
// the list
struct mlist *list;
list = malloc (sizeof(struct mlist));
LIST_INIT(list);
// create the elements
struct node *n1 = malloc (sizeof(struct node));
n1->content = 10;
struct node *n2 = malloc (sizeof(struct node));
n2->content = 20;
// insert element into the list
LIST_INSERT_HEAD(list, n1, entries);
LIST_INSERT_HEAD(list, n2, entries);
// loop over the list
struct node *np = NULL;
LIST_FOREACH(np, list, entries) {
printf ("elem : %d\n", np->content);
}
// remove elements from the list
LIST_REMOVE(n1, entries);
LIST_REMOVE(n2, entries);
// to be sure that nothing still is into the list
np = NULL;
LIST_FOREACH(np, list, entries) {
printf ("\033[31mSHOULD NOT BE PRINTED : %d\033[00m\n", np->content);
}
// free the elements then the list itself
free (n1);
free (n2);
free (list);
return EXIT_SUCCESS;
}