From 6c342ffdeee5353ecf78493c41ee23ef79cbd940 Mon Sep 17 00:00:00 2001 From: Tyge Lovset Date: Wed, 6 Oct 2021 07:55:07 +0200 Subject: Remove side-effects from i_valdel() invocations in case it's a macro func. --- examples/advanced.c | 2 +- examples/new_sptr.c | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'examples') diff --git a/examples/advanced.c b/examples/advanced.c index 70aef8e8..0466e0da 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -47,7 +47,7 @@ static inline VikingRaw viking_toRaw(const Viking* vk) { int main() { - c_autovar (cmap_vk vikings = cmap_vk_init(), cmap_vk_del(&vikings)) { + c_auto (cmap_vk, vikings) { c_apply_pair(cmap_vk, emplace, &vikings, { {{"Einar", "Norway"}, 20}, {{"Olaf", "Denmark"}, 24}, diff --git a/examples/new_sptr.c b/examples/new_sptr.c index 25eb6702..59512803 100644 --- a/examples/new_sptr.c +++ b/examples/new_sptr.c @@ -19,11 +19,12 @@ void Person_del(Person* p) { // ... #define i_val int +#define i_del(x) printf("del: %d\n", *(x)) #include -#define i_key_csptr csptr_int +#define i_val_csptr csptr_int #define i_tag iptr -#include +#include int main(void) { c_autovar (csptr_person p = csptr_person_make(Person_init("John", "Smiths")), csptr_person_del(&p)) @@ -32,11 +33,14 @@ int main(void) { printf("%s %s. uses: %u\n", q.get->name.str, q.get->last.str, *q.use_count); } - c_auto (csset_iptr, map) { - csset_iptr_insert(&map, csptr_int_make(2021)); - csset_iptr_insert(&map, csptr_int_make(2033)); + c_auto (cstack_iptr, stk) { + cstack_iptr_push(&stk, csptr_int_make(10)); + cstack_iptr_push(&stk, csptr_int_make(20)); + cstack_iptr_push(&stk, csptr_int_make(30)); + cstack_iptr_emplace(&stk, *cstack_iptr_top(&stk)); + cstack_iptr_emplace(&stk, *cstack_iptr_begin(&stk).ref); - c_foreach (i, csset_iptr, map) + c_foreach (i, cstack_iptr, stk) printf(" %d", *i.ref->get); puts(""); } -- cgit v1.2.3