summaryrefslogtreecommitdiffhomepage
path: root/examples/stack.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-05-18 22:08:47 +0200
committerTyge Løvset <[email protected]>2021-05-18 22:08:47 +0200
commit4578ae03cea28def01dc9f5fe882234857b1238e (patch)
treed57cd864da28f9d13c446e0730e2582c35556f0a /examples/stack.c
parenta8d94f4acea04681c89b46233f90bd8f4cee6ebf (diff)
downloadSTC-modified-4578ae03cea28def01dc9f5fe882234857b1238e.tar.gz
STC-modified-4578ae03cea28def01dc9f5fe882234857b1238e.zip
Added the new c_defer(), c_with(), c_withvar() macros into the examples.
Diffstat (limited to 'examples/stack.c')
-rw-r--r--examples/stack.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/examples/stack.c b/examples/stack.c
index 3bcf05dd..0815b580 100644
--- a/examples/stack.c
+++ b/examples/stack.c
@@ -11,17 +11,19 @@ using_cstack(c, cvec_c);
int main() {
cstack_i stack = cstack_i_init();
cstack_c chars = cstack_c_init();
+ c_defer (cstack_i_del(&stack), cstack_c_del(&chars))
+ {
+ c_forrange (i, int, 101)
+ cstack_i_push(&stack, i*i);
- c_forrange (i, int, 101)
- cstack_i_push(&stack, i*i);
+ printf("%d\n", *cstack_i_top(&stack));
- printf("%d\n", *cstack_i_top(&stack));
-
- c_forrange (i, int, 90)
- cstack_i_pop(&stack);
-
- c_foreach (i, cstack_i, stack)
- printf(" %d", *i.ref);
- puts("");
- printf("top: %d\n", *cstack_i_top(&stack));
+ c_forrange (i, int, 90)
+ cstack_i_pop(&stack);
+
+ c_foreach (i, cstack_i, stack)
+ printf(" %d", *i.ref);
+ puts("");
+ printf("top: %d\n", *cstack_i_top(&stack));
+ }
} \ No newline at end of file