summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-10-25 14:08:43 +0200
committerTyge Løvset <[email protected]>2022-10-25 14:08:43 +0200
commit89429e8e8242df35bc482c13c4a9f2b23e62e51d (patch)
tree2a5a82ec84e6e71299d455e5683bc9193b3fe6f2 /examples
parent538fdd51a7e530adf2ab31a76deb9ac8e52f525e (diff)
downloadSTC-modified-89429e8e8242df35bc482c13c4a9f2b23e62e51d.tar.gz
STC-modified-89429e8e8242df35bc482c13c4a9f2b23e62e51d.zip
More and hopefully final fixes of cbox/carc.
API change: _from = _make, _new => _from
Diffstat (limited to 'examples')
-rw-r--r--examples/box2.c12
-rw-r--r--examples/rawptr_elements.c2
2 files changed, 8 insertions, 6 deletions
diff --git a/examples/box2.c b/examples/box2.c
index f64eb239..03f7d8bd 100644
--- a/examples/box2.c
+++ b/examples/box2.c
@@ -30,12 +30,12 @@ struct {
#include <stc/cbox.h> // cbox_BoxPoint
Point origin(void) {
- return (Point){ .x=0.0, .y=0.0 };
+ return (Point){ .x=1.0, .y=2.0 };
}
cbox_Point boxed_origin(void) {
// Allocate this point on the heap, and return a pointer to it
- return cbox_Point_from((Point){ .x=0.0, .y=0.0 });
+ return cbox_Point_make((Point){ .x=2.0, .y=3.0 });
}
@@ -50,10 +50,10 @@ int main(void) {
// Declare auto-deleted box objects
c_auto (cbox_Rectangle, boxed_rectangle)
c_auto (cbox_Point, boxed_point)
- c_auto (cbox_BoxPoint, box_in_a_box)
+ c_auto (cbox_BoxPoint, box_in_a_box, boxbox2)
{
// Heap allocated rectangle
- boxed_rectangle = cbox_Rectangle_from((Rectangle){
+ boxed_rectangle = cbox_Rectangle_make((Rectangle){
.top_left = origin(),
.bottom_right = (Point){ .x=3.0, .y=-4.0 }
});
@@ -62,7 +62,9 @@ int main(void) {
boxed_point = cbox_Point_from(origin());
// Double indirection
- box_in_a_box = cbox_BoxPoint_from(boxed_origin());
+ box_in_a_box = cbox_BoxPoint_make(boxed_origin());
+ boxbox2 = cbox_BoxPoint_from(point); // !!
+ printf("boxbox2: x=%f\n", boxbox2.get->get->x);
printf("Point occupies %" c_ZU " bytes on the stack\n",
sizeof(point));
diff --git a/examples/rawptr_elements.c b/examples/rawptr_elements.c
index 095357ca..37f1fe32 100644
--- a/examples/rawptr_elements.c
+++ b/examples/rawptr_elements.c
@@ -46,7 +46,7 @@ int main()
puts("\nIBox map:");
- SIBoxMap_insert(&m2, cstr_from("Hello"), IBox_from(123));
+ SIBoxMap_insert(&m2, cstr_from("Hello"), IBox_make(123));
SIBoxMap_emplace(&m2, "World", 999);
c_forpair (name, number, SIBoxMap, m2)
printf("%s: %d\n", cstr_str(_.name), *_.number->get);