summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/intrusive.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/intrusive.c')
-rw-r--r--misc/examples/intrusive.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/misc/examples/intrusive.c b/misc/examples/intrusive.c
index acf4416d..4135317e 100644
--- a/misc/examples/intrusive.c
+++ b/misc/examples/intrusive.c
@@ -1,4 +1,4 @@
-// Example of intrusive list by using the node API and typesafe c_container_of().
+// Example of intrusive list by using the node API and typesafe c_CONTAINER_OF().
#include <stdio.h>
@@ -14,39 +14,39 @@
int main()
{
- c_auto (List2, list2)
+ c_AUTO (List2, list2)
{
List1 list1 = List1_init(); // should not be destroyed, list2 will destroy shared nodes.
- c_forlist (i, int, {6, 9, 3, 1, 7, 4, 5, 2, 8})
+ c_FORLIST (i, int, {6, 9, 3, 1, 7, 4, 5, 2, 8})
List2_push_back(&list2, (List1_node){NULL, *i.ref});
- c_foreach (i, List2, list2)
- List1_push_node_back(&list1, c_container_of(&i.ref->value, List1_node, value));
+ c_FOREACH (i, List2, list2)
+ List1_push_node_back(&list1, c_CONTAINER_OF(&i.ref->value, List1_node, value));
printf("list1:");
- c_foreach (i, List1, list1) printf(" %d", *i.ref);
+ c_FOREACH (i, List1, list1) printf(" %d", *i.ref);
printf("\nlist2:");
- c_foreach (i, List2, list2) printf(" %d", i.ref->value);
+ c_FOREACH (i, List2, list2) printf(" %d", i.ref->value);
printf("\nsort list1");
List1_sort(&list1);
printf("\nlist1:");
- c_foreach (i, List1, list1) printf(" %d", *i.ref);
+ c_FOREACH (i, List1, list1) printf(" %d", *i.ref);
printf("\nlist2:");
- c_foreach (i, List2, list2) printf(" %d", i.ref->value);
+ c_FOREACH (i, List2, list2) printf(" %d", i.ref->value);
printf("\nremove 5 from both lists in O(1) time");
List1_iter it1 = List1_find(&list1, 5);
if (it1.ref) {
List1_unlink_node_after(&list1, it1.prev);
- free(List2_unlink_node_after(&list2, c_container_of(it1.prev, List2_node, value)));
+ free(List2_unlink_node_after(&list2, c_CONTAINER_OF(it1.prev, List2_node, value)));
}
printf("\nlist1:");
- c_foreach (i, List1, list1) printf(" %d", *i.ref);
+ c_FOREACH (i, List1, list1) printf(" %d", *i.ref);
printf("\nlist2:");
- c_foreach (i, List2, list2) printf(" %d", i.ref->value);
+ c_FOREACH (i, List2, list2) printf(" %d", i.ref->value);
puts("");
}
}