diff options
| author | Tyge Løvset <[email protected]> | 2022-09-05 09:07:29 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-09-05 09:07:29 +0200 |
| commit | fc559ef64840fe54c0136f064cbfb2d3c055b692 (patch) | |
| tree | 3935236a6ff3f7cfc8db4e0b5cb96e3203197bbc /examples | |
| parent | 491a8cba3ee55a1200fc2de8ef3807dd8436f829 (diff) | |
| download | STC-modified-fc559ef64840fe54c0136f064cbfb2d3c055b692.tar.gz STC-modified-fc559ef64840fe54c0136f064cbfb2d3c055b692.zip | |
Added cstr_append_fmt().
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/box2.c | 8 | ||||
| -rw-r--r-- | examples/new_sptr.c | 12 |
2 files changed, 10 insertions, 10 deletions
diff --git a/examples/box2.c b/examples/box2.c index 75f9970f..28b4acff 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -35,7 +35,7 @@ Point origin(void) { cbox_Point boxed_origin(void) { // Allocate this point on the heap, and return a pointer to it - return cbox_Point_make((Point){ .x=0.0, .y=0.0 }); + return cbox_Point_from((Point){ .x=0.0, .y=0.0 }); } @@ -53,16 +53,16 @@ int main(void) { c_auto (cbox_BoxPoint, box_in_a_box) { // Heap allocated rectangle - boxed_rectangle = cbox_Rectangle_make((Rectangle){ + boxed_rectangle = cbox_Rectangle_from((Rectangle){ .top_left = origin(), .bottom_right = (Point){ .x=3.0, .y=-4.0 } }); // The output of functions can be boxed - boxed_point = cbox_Point_make(origin()); + boxed_point = cbox_Point_from(origin()); // Double indirection - box_in_a_box = cbox_BoxPoint_make(boxed_origin()); + box_in_a_box = cbox_BoxPoint_from(boxed_origin()); printf("Point occupies %" PRIuMAX " bytes on the stack\n", sizeof(point)); diff --git a/examples/new_sptr.c b/examples/new_sptr.c index 71222799..e3431d8a 100644 --- a/examples/new_sptr.c +++ b/examples/new_sptr.c @@ -2,7 +2,7 @@ struct Person { cstr name, last; } typedef Person; -Person Person_new(const char* name, const char* last) { +Person Person_from(const char* name, const char* last) { return (Person){.name = cstr_from(name), .last = cstr_from(last)}; } Person Person_clone(Person p) { @@ -32,18 +32,18 @@ int main(void) { c_auto (carc_person, p, q, r, s) { puts("Ex1"); - p = carc_person_make(Person_new("John", "Smiths")); + p = carc_person_from(Person_from("John", "Smiths")); q = carc_person_clone(p); r = carc_person_clone(p); - s = carc_person_make(Person_clone(*p.get)); // deep copy + s = carc_person_from(Person_clone(*p.get)); // deep copy printf("%s %s. uses: %lu\n", cstr_str(&r.get->name), cstr_str(&s.get->last), *p.use_count); } c_auto (cstack_iptr, stk) { puts("Ex2"); - cstack_iptr_push(&stk, SPtr_make(10)); - cstack_iptr_push(&stk, SPtr_make(20)); - cstack_iptr_push(&stk, SPtr_make(30)); + cstack_iptr_push(&stk, SPtr_from(10)); + cstack_iptr_push(&stk, SPtr_from(20)); + cstack_iptr_push(&stk, SPtr_from(30)); cstack_iptr_push(&stk, SPtr_clone(*cstack_iptr_top(&stk))); cstack_iptr_push(&stk, SPtr_clone(*cstack_iptr_begin(&stk).ref)); |
