diff options
| author | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2023-03-26 00:27:45 +0100 |
| commit | eb85069b669e754836b9d4587ba03d3af1a5e975 (patch) | |
| tree | 45c9a0d3fe40c59a8b33ae8ecd2e7aa78bef6240 /misc/examples/person_arc.c | |
| parent | e8be14dfc894eeac859f0287d4d5b4f4745c0585 (diff) | |
| download | STC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.tar.gz STC-modified-eb85069b669e754836b9d4587ba03d3af1a5e975.zip | |
development branch for 4.2
Removed uses of c_auto and c_with in documentation examples and code examples. Still using c_defer a few places.
Renamed c11/fmt.h to c11/print.h.
Some additions in ccommon.h, e.g. c_const_cast(T, x).
Improved docs.
Diffstat (limited to 'misc/examples/person_arc.c')
| -rw-r--r-- | misc/examples/person_arc.c | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/misc/examples/person_arc.c b/misc/examples/person_arc.c index a7bf2a6f..620d311f 100644 --- a/misc/examples/person_arc.c +++ b/misc/examples/person_arc.c @@ -39,13 +39,15 @@ void Person_drop(Person* p) { int main() { - c_auto (Persons, vec) - c_auto (PSPtr, p, q) - { - p = PSPtr_from(Person_make("Laura", "Palmer")); - - // We want a deep copy -- PSPtr_clone(p) only shares! - q = PSPtr_from(Person_clone(*p.get)); + PSPtr p = PSPtr_from(Person_make("Laura", "Palmer")); + PSPtr q = PSPtr_from(Person_clone(*p.get)); // deep copy + Persons vec = {0}; + + c_defer( + PSPtr_drop(&p), + PSPtr_drop(&q), + Persons_drop(&vec) + ){ cstr_assign(&q.get->name, "Leland"); printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last)); @@ -65,10 +67,9 @@ int main() puts(""); // Look-up Audrey! - c_with (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) { - const PSPtr *v = Persons_get(&vec, a); - if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last)); - } - puts(""); + Person a = Person_make("Audrey", "Home"); + const PSPtr *v = Persons_get(&vec, a); + if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last)); + Person_drop(&a); } } |
