diff options
| author | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
|---|---|---|
| committer | realtradam <[email protected]> | 2023-04-12 15:55:33 -0400 |
| commit | 0841165881871ee01b782129be681209aeed2423 (patch) | |
| tree | 8a76b61dcaab381b6b42305201ae8b6259f6b6c0 /misc/examples/box2.c | |
| parent | 554f3e8acf7855b5d6a90cc68cefb7445460b03c (diff) | |
| parent | 0516aa3ae823ed9a22b2c5f776948c8447c32c31 (diff) | |
| download | STC-modified-0841165881871ee01b782129be681209aeed2423.tar.gz STC-modified-0841165881871ee01b782129be681209aeed2423.zip | |
Merge branch 'master' into modified
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", |
