diff options
Diffstat (limited to 'misc/examples/box2.c')
| -rw-r--r-- | misc/examples/box2.c | 34 |
1 files changed, 15 insertions, 19 deletions
diff --git a/misc/examples/box2.c b/misc/examples/box2.c index f7d21976..cba255d2 100644 --- a/misc/examples/box2.c +++ b/misc/examples/box2.c @@ -40,31 +40,27 @@ cbox_Point boxed_origin(void) { int main(void) { // Stack allocated variables Point point = origin(); - Rectangle rectangle = (Rectangle){ + Rectangle rectangle = { .top_left = origin(), .bottom_right = { .x=3.0, .y=-4.0 } }; - // Declare RAII'ed box objects - c_auto (cbox_Rectangle, boxed_rectangle) - c_auto (cbox_Point, boxed_point) - c_auto (BoxBoxPoint, box_in_a_box) - { - // Heap allocated rectangle - boxed_rectangle = cbox_Rectangle_make((Rectangle){ - .top_left = origin(), - .bottom_right = { .x=3.0, .y=-4.0 } - }); + // Heap allocated rectangle + cbox_Rectangle boxed_rectangle = cbox_Rectangle_make((Rectangle){ + .top_left = origin(), + .bottom_right = { .x=3.0, .y=-4.0 } + }); + // The output of functions can be boxed + cbox_Point boxed_point = cbox_Point_make(origin()); - // The output of functions can be boxed - boxed_point = cbox_Point_make(origin()); + // Can use from(raw) and toraw instead: + BoxBoxPoint box_in_a_box = BoxBoxPoint_from(origin()); - // Double indirection - //box_in_a_box = BoxBoxPoint_make(boxed_origin()); - //printf("box_in_a_box: x = %g\n", box_in_a_box.get->get->x); - - // Can use from(raw) and toraw instead: - box_in_a_box = BoxBoxPoint_from(origin()); + c_defer( + BoxBoxPoint_drop(&box_in_a_box), + cbox_Point_drop(&boxed_point), + cbox_Rectangle_drop(&boxed_rectangle) + ){ printf("box_in_a_box: x = %g\n", BoxBoxPoint_toraw(&box_in_a_box).x); printf("Point occupies %d bytes on the stack\n", |
