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/box.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/box.c')
| -rw-r--r-- | misc/examples/box.c | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/misc/examples/box.c b/misc/examples/box.c index da13501f..9954883c 100644 --- a/misc/examples/box.c +++ b/misc/examples/box.c @@ -37,32 +37,32 @@ void Person_drop(Person* p) { int main() { - c_auto (Persons, vec) - c_auto (PBox, p, q) - { - p = PBox_from(Person_make("Laura", "Palmer")); - q = PBox_clone(p); - cstr_assign(&q.get->name, "Leland"); + Persons vec = {0}; + PBox p = PBox_from(Person_make("Laura", "Palmer")); + PBox q = PBox_clone(p); + cstr_assign(&q.get->name, "Leland"); - printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last)); - printf("copy: %s %s\n", cstr_str(&q.get->name), cstr_str(&q.get->last)); + printf("orig: %s %s\n", cstr_str(&p.get->name), cstr_str(&p.get->last)); + printf("copy: %s %s\n", cstr_str(&q.get->name), cstr_str(&q.get->last)); - Persons_emplace(&vec, Person_make("Dale", "Cooper")); - Persons_emplace(&vec, Person_make("Audrey", "Home")); + Persons_emplace(&vec, Person_make("Dale", "Cooper")); + Persons_emplace(&vec, Person_make("Audrey", "Home")); - // NB! Clone/share p and q in the Persons container. - Persons_push(&vec, PBox_clone(p)); - Persons_push(&vec, PBox_clone(q)); + // NB! Clone/share p and q in the Persons container. + Persons_push(&vec, PBox_clone(p)); + Persons_push(&vec, PBox_clone(q)); - c_foreach (i, Persons, vec) - printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last)); - puts(""); + c_foreach (i, Persons, vec) + printf("%s %s\n", cstr_str(&i.ref->get->name), cstr_str(&i.ref->get->last)); + puts(""); - // Look-up Audrey! Create a temporary Person for lookup. - c_with (Person a = Person_make("Audrey", "Home"), Person_drop(&a)) { - const PBox *v = Persons_get(&vec, a); // lookup - if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last)); - } - puts(""); - } + // Look-up Audrey! Create a temporary Person for lookup. + Person a = Person_make("Audrey", "Home"); + const PBox *v = Persons_get(&vec, a); // lookup + if (v) printf("found: %s %s\n", cstr_str(&v->get->name), cstr_str(&v->get->last)); + + Person_drop(&a); + PBox_drop(&p); + PBox_drop(&q); + Persons_drop(&vec); } |
