From bdea38e432d109ba416d7f980f124da285d69a4f Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Thu, 26 Nov 2020 15:08:07 +0100 Subject: Removed stc/cfmt.h, as _Generic requires C11. I have made it a gist: https://gist.github.com/tylov/bcc956a4779f1d14204e66a14f17beb9 All examples are reverted to use printf() instead of c_print(). --- README.md | 68 ++++++++++++++++++---------------------- examples/advanced.c | 4 +-- examples/benchmark.c | 20 ++++++------ examples/birthday.c | 9 +++--- examples/bits.c | 33 ++++++++++---------- examples/complex.c | 8 ++--- examples/demos.c | 84 +++++++++++++++++++++++++------------------------- examples/ex_gaussian.c | 6 ++-- examples/heap.c | 11 +++---- examples/inits.c | 24 +++++++++------ examples/list.c | 21 ++++++------- examples/mapmap.c | 4 +-- examples/phonebook.c | 4 +-- examples/prime.c | 14 ++++----- examples/priority.c | 5 +-- examples/ptr.c | 12 ++++---- examples/queue.c | 6 ++-- examples/random.c | 28 ++++++++--------- examples/rngtest.c | 21 ++++++------- examples/share_ptr.c | 17 +++++----- examples/share_ptr2.c | 8 ++--- examples/stack.c | 14 ++++----- examples/words.c | 6 ++-- stc/carray.h | 6 ++-- 24 files changed, 214 insertions(+), 219 deletions(-) diff --git a/README.md b/README.md index a4831915..7137a701 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,6 @@ An elegant, fully typesafe, generic, customizable, user-friendly, consistent, an - **stc/cptr.h** - Support for pointers in containers, and a reference counted shared pointer **csptr**. - **stc/coption.h** - Implementation of a **getopt_long()**-like function, *coption_get()*, to parse command line arguments. - **stc/crandom.h** - A few very efficent modern random number generators *pcg32* and my own *64-bit PRNG* inspired by *sfc64*. Both uniform and normal distributions. -- **stc/cfmt.h** - Implementation of **c_print()** with c++20 *std::format*-like formatting, including automatic detection of argument types. - **stc/ccommon.h** - A common include file with a few general definitions. The usage of the containers is quite similar to the C++ standard containers, so it should be easy if you are familiar with them. @@ -25,7 +24,6 @@ The usage of the containers is quite similar to the C++ standard containers, so All containers mentioned above, except cstr_t and cbitset_t, are generic and therefore typesafe (similar to templates in C++). No casting is used. A simple example: ```C #include -#include using_cvec(i, int); @@ -33,9 +31,8 @@ int main(void) { cvec_i vec = cvec_i_init(); cvec_i_push_back(&vec, 1); cvec_i_push_back(&vec, 2); - c_foreach (i, cvec_i, vec) - c_print(1, " {}", *i.val); + printf(" %d", *i.val); cvec_i_del(&vec); } ``` @@ -61,7 +58,7 @@ int main(void) { cvec_u_push_back(&vec, (User) {cstr_from("admin"), 0}); // cstr_from() allocates string memory cvec_u_push_back(&vec, (User) {cstr_from("usera"), 1}); c_foreach (i, cvec_u, vec) - c_print(1, "{}: {}\n", i.val->name.str, i.val->id); + printf("%s: %d\n", i.val->name.str, i.val->id); cvec_u_del(&vec); // free everything } ``` @@ -194,7 +191,7 @@ The examples folder contains further examples. **cvec** of *int64_t*. ```C #include -#include +#include using_cvec(ix, int64_t); // ix is just an example type tag name. @@ -211,7 +208,7 @@ int main() { bignums.data[i] /= i; // make them smaller c_foreach (i, cvec_ix, bignums) - c_print(1, " {}", *i.val); + printf(" %d", *i.val); cvec_ix_del(&bignums); } // Output: @@ -219,7 +216,7 @@ int main() { ``` **cvec** of *cstr_t*. ```C -#include +#include #include using_cvec_str(); @@ -234,10 +231,10 @@ int main() { cstr_t tmp = cstr_from_fmt("%d elements so far", cvec_str_size(names)); cvec_str_push_back(&names, tmp); // tmp is moved to names, do not del() it. - c_print(1, "{}\n", names.data[1].str); // Access the second element + printf("%s\n", names.data[1].str); // Access the second element c_foreach (i, cvec_str, names) - c_print(1, "item: {}\n", i.val->str); + printf("item: %s\n", i.val->str); cvec_str_del(&names); } // Output: @@ -248,29 +245,28 @@ item: 2 elements so far ``` **cstr** string example. ```C -#include +#include int main() { cstr_t s1 = cstr_from("one-nine-three-seven-five"); - c_print(1, "{}.\n", s1.str); + printf("%s.\n", s1.str); cstr_insert(&s1, 3, "-two"); - c_print(1, "{}.\n", s1.str); + printf("%s.\n", s1.str); cstr_erase(&s1, 7, 5); // -nine - c_print(1, "{}.\n", s1.str); + printf("%s.\n", s1.str); cstr_replace(&s1, cstr_find(&s1, "seven"), 5, "four"); - c_print(stderr, "{}.\n", s1.str); + printf("%s.\n", s1.str); // reassign: cstr_assign(&s1, "one two three four five six seven"); cstr_append(&s1, " eight"); printf("append: %s\n", s1.str); - cstr_t full_path cstr_init; - c_print(&full_path, "{}/{}.{}", "directory", "filename", "ext"); - c_print(2, "{}\n", full_path.str); // 2 = stderr + cstr_t full_path = cstr_from_fmt("%s/%s.%s", "directory", "filename", "ext"); + printf("%s\n", full_path.str); c_del(cstr, &s1, &full_path); } @@ -286,7 +282,7 @@ directory/filename.ext ```C #include #include -#include +#include using_cmap(ii, int, int); using_cmap_str(); @@ -297,7 +293,7 @@ int main() { cmap_ii_put(&nums, 8, 64); // similar to insert_or_assign() cmap_ii_emplace(&nums, 11, 121); - c_print(1, "{}\n", cmap_ii_find(&nums, 8)->second); + printf("%d\n", cmap_ii_find(&nums, 8)->second); cmap_ii_del(&nums); // -- map of str -- @@ -307,9 +303,9 @@ int main() { cmap_str_emplace(&strings, "Sunny", "afternoon"); c_push_items(&strings, cmap_str, { {"Eleven", "XI"}, {"Six", "VI"} }); - c_print(1, "size = {}\n", cmap_str_size(strings)); + printf("size = %zu\n", cmap_str_size(strings)); c_foreach (i, cmap_str, strings) - c_print(1, "{}: {}\n", i.val->first.str, i.val->second.str); + printf("%s: %s\n", i.val->first.str, i.val->second.str); cmap_str_del(&strings); // frees all strings and map. } // Output: @@ -323,7 +319,7 @@ Eleven: XI ``` **cset** of *cstr*. ```C -#include +#include #include using_cset_str(); // cstr set. See the discussion above. @@ -338,7 +334,7 @@ int main() { // iterate the set of cstr_t values: c_foreach (i, cset_str, words) - c_print(1, "{} ", i.val->str); + printf("%s ", i.val->str); cset_str_del(&words); } // Output: @@ -347,7 +343,6 @@ Hello World **clist** of *int64_t*. Similar to c++ *std::forward_list*, but can do both *push_front()* and *push_back()* as well as *pop_front()*. ```C #include -#include #include using_clist(fx, double); @@ -365,13 +360,13 @@ int main() { printf("initial: "); c_foreach (i, clist_fx, list) - c_print(1, " {:.16}", *i.val); + printf(" %g", *i.val); clist_fx_sort(&list); // mergesort O(n*log n) printf("\nsorted: "); c_foreach (i, clist_fx, list) - c_print(1, " {:10f}", *i.val); + printf(" %g", *i.val); clist_fx_del(&list); } @@ -382,7 +377,6 @@ sorted: 1 2 3 4 5 6 7 8 9 10 20 30 40 50 60 70 80 90 **cpqueue** priority queue demo: ```C #include -#include #include #include @@ -403,7 +397,7 @@ int main() // Extract and disply the fifty smallest. c_forrange (50) { - c_print(1, "{} ", *cpqueue_i_top(&heap)); + printf("%zd ", *cpqueue_i_top(&heap)); cpqueue_i_pop(&heap); } cpqueue_i_del(&heap); @@ -414,7 +408,6 @@ int main() **cqueue** adapter container. Uses singly linked list as representation. ```C #include -#include #include using_clist(i, int); @@ -431,7 +424,7 @@ int main() { cqueue_i_pop(&queue); c_foreach (i, cqueue_i, queue) - c_print(1, " {}", *i.val); + printf(" %d", *i.val); cqueue_i_del(&queue); } @@ -442,7 +435,6 @@ int main() { ```C #include #include -#include using_carray(f, float); @@ -454,9 +446,9 @@ int main() carray1f a1 = carray3f_at2(&a3, 5, 4); // sub-array a3[5][4] (no data copy). carray2f a2 = carray3f_at1(&a3, 5); // sub-array a3[5] - c_print(stdout, "{}\n", *carray1f_at(&a1, 3)); // a1[3] (3.14f) - c_print(stdout, "{}\n", *carray2f_at(&a2, 4, 3)); // a2[4][3] (3.14f) - c_print(stdout, "{}\n", *carray3f_at(&a3, 5, 4, 3)); // a3[5][4][3] (3.14f) + printf("%f\n", *carray1f_at(&a1, 3)); // a1[3] (3.14f) + printf("%f\n", *carray2f_at(&a2, 4, 3)); // a2[4][3] (3.14f) + printf("%f\n", *carray3f_at(&a3, 5, 4, 3)); // a3[5][4][3] (3.14f) // ... carray1f_del(&a1); // does nothing, since it is a sub-array. carray2f_del(&a2); // same. @@ -507,7 +499,7 @@ Code: #include #include #include -#include +#include #include using_cmap(ii, int, int); @@ -571,10 +563,10 @@ void display_hist(cvec_mi hist, int scale, int mean, int stddev) int k = (int) (i.val->second * stddev * scale * 25ull / 10 / n); if (k > 0) { cstr_take(&bar, cstr_with_size(k, '*')); - c_print(1, "{:4} {}\n", i.val->first, bar.str); + printf("%4d %s\n", i.val->first, bar.str); } } - c_print(1, "Normal distribution with mean={}, stddev={}. '*' = {:.0f} samples out of {}.\n", + printf("Normal distribution with mean=%d, stddev=%d. '*' = %.0f samples out of %d.\n", mean, stddev, n / (2.5 * stddev * scale), n); cstr_del(&bar); } diff --git a/examples/advanced.c b/examples/advanced.c index d559e154..280d5ce4 100644 --- a/examples/advanced.c +++ b/examples/advanced.c @@ -11,7 +11,7 @@ * of the Viking struct, to simplfy insert and lookup in the map. */ #include -#include +#include // Viking data struct ----------------------- @@ -73,7 +73,7 @@ int main() cmap_vk_emplace(&vikings, einar, 0).first->second += 5; // again c_foreach (k, cmap_vk, vikings) { - c_print(1, "{} of {} has {} HP\n", k.val->first.name.str, k.val->first.country.str, k.val->second); + printf("%s of %s has %d HP\n", k.val->first.name.str, k.val->first.country.str, k.val->second); } cmap_vk_del(&vikings); } diff --git a/examples/benchmark.c b/examples/benchmark.c index ab500429..4b4a50dd 100644 --- a/examples/benchmark.c +++ b/examples/benchmark.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include "others/khash.h" @@ -150,7 +150,7 @@ int rr = RR; erased += M##_ERASE(X, RAND(rr)); \ } \ difference = clock() - before; \ - c_print(1, #M ": time: {:5.02f}, sum: {}, erased {}, size: {}, buckets: {:8}\n", \ + printf(#M ": time: %5.02f, sum: %zu, erased %zu, size: %zu, buckets: %8zu\n", \ (float) difference / CLOCKS_PER_SEC, checksum, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \ M##_CLEAR(X); \ } @@ -165,7 +165,7 @@ int rr = RR; for (size_t i = 0; i < N2; ++i) \ erased += M##_ERASE(X, i); \ difference = clock() - before; \ - c_print(1, #M ": time: {:5.02f}, erased {}, size: {}, buckets: {:8}\n", \ + printf(#M ": time: %5.02f, erased %zu, size: %zu, buckets: %8zu\n", \ (float) difference / CLOCKS_PER_SEC, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \ M##_CLEAR(X); \ } @@ -182,7 +182,7 @@ int rr = RR; for (size_t i = 0; i < N3; ++i) \ erased += M##_ERASE(X, RAND(rr)); \ difference = clock() - before; \ - c_print(1, #M ": time: {:5.02f}, erased {}, size: {}, buckets: {:8}\n", \ + printf(#M ": time: %5.02f, erased %zu, size: %zu, buckets: %8zu\n", \ (float) difference / CLOCKS_PER_SEC, erased, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \ M##_CLEAR(X); \ } @@ -198,7 +198,7 @@ int rr = RR; for (int k=0; k<5; k++) M##_FOR (X, i) \ sum += M##_ITEM(X, i); \ difference = clock() - before; \ - c_print(1, #M ": time: {:5.02f}, sum {}, size: {}, buckets: {:8}\n", \ + printf(#M ": time: %5.02f, sum %zu, size: %zu, buckets: %8zu\n", \ (float) difference / CLOCKS_PER_SEC, sum, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X)); \ M##_CLEAR(X); \ } @@ -218,16 +218,16 @@ int main(int argc, char* argv[]) { rr = argc == 2 ? atoi(argv[1]) : RR; seed = time(NULL); - c_print(1, "\nRandom keys are in range [0, 2^{}), seed = {}:\n", rr, seed); - c_print(1, "\nUnordered maps: {} repeats of Insert random key + try to remove a random key:\n", N1); + printf("\nRandom keys are in range [0, 2^%d), seed = %zu:\n", rr, seed); + printf("\nUnordered maps: %d repeats of Insert random key + try to remove a random key:\n", N1); RUN_TEST(1) - c_print(1, "\nUnordered maps: Insert {} index keys, then remove them in same order:\n", N2); + printf("\nUnordered maps: Insert %d index keys, then remove them in same order:\n", N2); RUN_TEST(2) - c_print(1, "\nUnordered maps: Insert {} random keys, then remove them in same order:\n", N3); + printf("\nUnordered maps: Insert %d random keys, then remove them in same order:\n", N3); RUN_TEST(3) - c_print(1, "\nUnordered maps: Iterate {} random keys:\n", N4); + printf("\nUnordered maps: Iterate %d random keys:\n", N4); RUNX_TEST(4) } diff --git a/examples/birthday.c b/examples/birthday.c index fd7f9f46..54ffa30e 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -5,7 +5,6 @@ #include #include #include -#include using_cmap(ic, uint64_t, uint8_t); @@ -22,10 +21,10 @@ void repeats(void) c_forrange (i, N) { uint64_t k = crand_i64(&rng) & mask; int v = ++cmap_ic_emplace(&m, k, 0).first->second; - if (v > 1) c_print(1, "{}: {:x} - {}\n", i, k, v); + if (v > 1) printf("%zu: %llx - %d\n", i, k, v); } float diff = (float) (clock() - now) / CLOCKS_PER_SEC; - c_print(1, "{}", diff); + printf("%.02f", diff); } @@ -50,9 +49,9 @@ void distribution(void) sum /= map.size; c_foreach (i, cmap_x, map) - c_print(1, "{}: {} - {}\n", i.val->first, i.val->second, sum); + printf("%u: %zu - %zu\n", i.val->first, i.val->second, sum); - c_print(1, "{:.02}\n", diff); + printf("%.02f\n", diff); } int main() diff --git a/examples/bits.c b/examples/bits.c index 8e1533cc..1b12f238 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -1,19 +1,18 @@ #include #include -#include int main() { cbitset_t set = cbitset_with_size(23, true); - c_print(1, "count {}, {}\n", cbitset_count(set), set.size); + printf("count %zu, %zu\n", cbitset_count(set), set.size); cbitset_reset(&set, 9); cbitset_resize(&set, 43, false); c_withbuffer (str, char, set.size + 1) - c_print(1, " str: {}\n", cbitset_to_str(set, str, 0, -1)); + printf(" str: %s\n", cbitset_to_str(set, str, 0, -1)); - c_print(1, "{:4}: ", set.size); + printf("%4zu: ", set.size); c_forrange (i, int, set.size) - c_print(1, "{}", cbitset_test(set, i)); + printf("%d", cbitset_test(set, i)); puts(""); cbitset_set(&set, 28); @@ -21,36 +20,36 @@ int main() { cbitset_resize(&set, 93, false); cbitset_resize(&set, 102, true); cbitset_set_value(&set, 99, false); - c_print(1, "{:4}: ", set.size); + printf("%4zu: ", set.size); c_forrange (i, int, set.size) - c_print(1, "{}", cbitset_test(set, i)); + printf("%d", cbitset_test(set, i)); puts("\nIterator:"); - c_print(1, "{:4}: ", set.size); + printf("%4zu: ", set.size); c_foreach (i, cbitset, set) - c_print(1, "{}", cbitset_itval(i)); - puts(""); + printf("%d", cbitset_itval(i)); + puts(""); cbitset_t s2 = cbitset_clone(set); cbitset_flip_all(&s2); cbitset_set(&s2, 16); cbitset_set(&s2, 17); - cbitset_set(&s2, 18); - c_print(1, " new: "); + cbitset_set(&s2, 18); + printf(" new: "); c_forrange (i, int, s2.size) - c_print(1, "{}", cbitset_test(s2, i)); + printf("%d", cbitset_test(s2, i)); puts(""); - c_print(1, " xor: "); + printf(" xor: "); cbitset_xor_with(&set, s2); c_forrange (i, int, set.size) - c_print(1, "{}", cbitset_test(set, i)); + printf("%d", cbitset_test(set, i)); puts(""); cbitset_set_all(&set, false); - c_print(1, "{:4}: ", set.size); + printf("%4zu: ", set.size); c_forrange (i, int, set.size) - c_print(1, "{}", cbitset_test(set, i)); + printf("%d", cbitset_test(set, i)); puts(""); cbitset_del(&s2); diff --git a/examples/complex.c b/examples/complex.c index 9f12b424..19e5ae2e 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -1,9 +1,9 @@ -#include +#include #include #include #include -void check_del(float* v) {c_print(1, "destroy {}\n", *v);} +void check_del(float* v) {printf("destroy %g\n", *v);} using_carray(f, float, check_del); // normally omit the last argument - float type need no destroy. using_clist(y, carray2f, carray2f_del, c_no_compare); @@ -18,7 +18,7 @@ int main() { { // Construct. carray2f table = carray2f_init(ydim, xdim, 0.f); - c_print(1, "table: ({}, {})\n", carray2_ydim(table), carray2_xdim(table)); + printf("table: (%zu, %zu)\n", carray2_ydim(table), carray2_xdim(table)); clist_y tableList = clist_inits; // Put in some data. cmap_g listMap = cmap_inits; @@ -30,7 +30,7 @@ int main() { } { // Access the data entry carray2f table = *clist_y_back(&cmap_g_find(&cmap_s_find(&myMap, strKey)->second, tableKey)->second); - c_print(1, "value ({}, {}) is: {}\n", y, x, *carray2f_at(&table, y, x)); + printf("value (%d, %d) is: %f\n", y, x, *carray2f_at(&table, y, x)); } cmap_s_del(&myMap); // free up everything! diff --git a/examples/demos.c b/examples/demos.c index e6649af6..7e8ef094 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -2,33 +2,33 @@ #include #include #include -#include +#include void stringdemo1() { - c_print(1, "\nSTRINGDEMO1\n"); + printf("\nSTRINGDEMO1\n"); cstr_t cs = cstr_from("one-nine-three-seven-five"); - c_print(1, "{}.\n", cs.str); + printf("%s.\n", cs.str); cstr_insert(&cs, 3, "-two"); - c_print(1, "{}.\n", cs.str); + printf("%s.\n", cs.str); cstr_erase(&cs, 7, 5); // -nine - c_print(1, "{}.\n", cs.str); + printf("%s.\n", cs.str); cstr_replace(&cs, cstr_find(cs, "seven"), 5, "four"); - c_print(1, "{}.\n", cs.str); + printf("%s.\n", cs.str); cstr_take(&cs, cstr_from_fmt("%s *** %s", cs.str, cs.str)); - c_print(1, "{}.\n", cs.str); + printf("%s.\n", cs.str); - c_print(1, "find \"four\": {}\n", cs.str + cstr_find(cs, "four")); + printf("find \"four\": %s\n", cs.str + cstr_find(cs, "four")); // reassign: cstr_assign(&cs, "one two three four five six seven"); cstr_append(&cs, " eight"); - c_print(1, "append: {}\n", cs.str); + printf("append: %s\n", cs.str); cstr_del(&cs); } @@ -38,17 +38,17 @@ using_cvec(ix, int64_t); // ix is just an example tag name. void vectordemo1() { - c_print(1, "\nVECTORDEMO1\n"); + printf("\nVECTORDEMO1\n"); cvec_ix bignums = cvec_inits; // = (cvec_ix) cvec_inits; if initializing after declaration. cvec_ix_reserve(&bignums, 100); - c_forrange (i, 101) + for (size_t i = 0; i<=100; ++i) cvec_ix_push_back(&bignums, i * i * i); - c_print(1, "erase - {}: {}\n", 100, bignums.data[100]); + printf("erase - %d: %zu\n", 100, bignums.data[100]); cvec_ix_pop_back(&bignums); // erase the last - c_forrange (i, cvec_size(bignums)) { - if (i >= 90) c_print(1, "{}: {}\n", i, bignums.data[i]); + for (size_t i = 0; i < cvec_size(bignums); ++i) { + if (i >= 90) printf("%zu: %zu\n", i, bignums.data[i]); } cvec_ix_del(&bignums); } @@ -59,17 +59,17 @@ using_cvec_str(); void vectordemo2() { - c_print(1, "\nVECTORDEMO2\n"); + printf("\nVECTORDEMO2\n"); cvec_str names = cvec_inits; cvec_str_emplace_back(&names, "Mary"); cvec_str_emplace_back(&names, "Joe"); cvec_str_emplace_back(&names, "Chris"); cstr_assign(&names.data[1], "Jane"); // replace Joe - c_print(1, "names[1]: {}\n", names.data[1].str); + printf("names[1]: %s\n", names.data[1].str); cvec_str_sort(&names); // Sort the array c_foreach (i, cvec_str, names) - c_print(1, "sorted: {}\n", i.val->str); + printf("sorted: %s\n", i.val->str); cvec_str_del(&names); } @@ -77,18 +77,18 @@ using_clist(ix, int); void listdemo1() { - c_print(1, "\nLISTDEMO1\n"); + printf("\nLISTDEMO1\n"); clist_ix nums = clist_inits, nums2 = clist_inits; - c_forrange (i, 10) + for (int i = 0; i < 10; ++i) clist_ix_push_back(&nums, i); - c_forrange (i, int, 100, 110) + for (int i = 100; i < 110; ++i) clist_ix_push_back(&nums2, i); c_foreach (i, clist_ix, nums) - c_print(1, "value: {}\n", *i.val); + printf("value: %d\n", *i.val); /* merge/append nums2 to nums */ clist_ix_splice_front(&nums, &nums2); c_foreach (i, clist_ix, nums) - c_print(1, "spliced: {}\n", *i.val); + printf("spliced: %d\n", *i.val); *clist_ix_find(&nums, 100).val *= 10; clist_ix_sort(&nums); // Sort the array @@ -96,7 +96,7 @@ void listdemo1() clist_ix_pop_front(&nums); clist_ix_push_front(&nums, -99); c_foreach (i, clist_ix, nums) - c_print(1, "sorted: {}\n", *i.val); + printf("sorted: %d\n", *i.val); clist_ix_del(&nums); } @@ -104,13 +104,13 @@ using_cset(i, int); void setdemo1() { - c_print(1, "\nSETDEMO1\n"); + printf("\nSETDEMO1\n"); cset_i nums = cset_inits; cset_i_insert(&nums, 8); cset_i_insert(&nums, 11); c_foreach (i, cset_i, nums) - c_print(1, "set: {}\n", *i.val); + printf("set: %d\n", *i.val); cset_i_del(&nums); } @@ -119,11 +119,11 @@ using_cmap(ii, int, int); void mapdemo1() { - c_print(1, "\nMAPDEMO1\n"); + printf("\nMAPDEMO1\n"); cmap_ii nums = cmap_inits; cmap_ii_put(&nums, 8, 64); cmap_ii_put(&nums, 11, 121); - c_print(1, "val 8: {}\n", *cmap_ii_at(&nums, 8)); + printf("val 8: %d\n", *cmap_ii_at(&nums, 8)); cmap_ii_del(&nums); } @@ -132,7 +132,7 @@ using_cmap_strkey(si, int); // Shorthand macro for the general using_cmap expans void mapdemo2() { - c_print(1, "\nMAPDEMO2\n"); + printf("\nMAPDEMO2\n"); cmap_si nums = cmap_inits; cmap_si_put(&nums, "Hello", 64); cmap_si_put(&nums, "Groovy", 121); @@ -140,11 +140,11 @@ void mapdemo2() // iterate the map: for (cmap_si_iter_t i = cmap_si_begin(&nums); i.val != cmap_si_end(&nums).val; cmap_si_next(&i)) - c_print(1, "long: {}: {}\n", i.val->first.str, i.val->second); + printf("long: %s: %d\n", i.val->first.str, i.val->second); // or rather use the short form: c_foreach (i, cmap_si, nums) - c_print(1, "short: {}: {}\n", i.val->first.str, i.val->second); + printf("short: %s: %d\n", i.val->first.str, i.val->second); cmap_si_del(&nums); } @@ -154,20 +154,20 @@ using_cmap_str(); void mapdemo3() { - c_print(1, "\nMAPDEMO3\n"); + printf("\nMAPDEMO3\n"); cmap_str table = cmap_inits; cmap_str_put(&table, "Map", "test"); cmap_str_put(&table, "Make", "my"); cmap_str_put(&table, "Sunny", "day"); cmap_str_value_t *e = cmap_str_find(&table, "Make"); c_foreach (i, cmap_str, table) - c_print(1, "entry: {}: {}\n", i.val->first.str, i.val->second.str); - c_print(1, "size {}: remove: Make: {}\n", cmap_size(table), e->second.str); + printf("entry: %s: %s\n", i.val->first.str, i.val->second.str); + printf("size %zu: remove: Make: %s\n", cmap_size(table), e->second.str); cmap_str_erase(&table, "Make"); - c_print(1, "size {}\n", cmap_size(table)); + printf("size %zu\n", cmap_size(table)); c_foreach (i, cmap_str, table) - c_print(1, "entry: {}: {}\n", i.val->first.str, i.val->second.str); + printf("entry: %s: %s\n", i.val->first.str, i.val->second.str); cmap_str_del(&table); // frees key and value cstrs, and hash table. } @@ -176,22 +176,22 @@ using_carray(f, float); void arraydemo1() { - c_print(1, "\nARRAYDEMO1\n"); + printf("\nARRAYDEMO1\n"); carray3f a3 = carray3f_init(30, 20, 10, 0.0f); *carray3f_at(&a3, 5, 4, 3) = 10.2f; // a3[5][4][3] carray2f a2 = carray3f_at1(&a3, 5); // sub-array reference: a2 = a3[5] carray1f a1 = carray3f_at2(&a3, 5, 4); // sub-array reference: a1 = a3[5][4] - c_print(1, "a3: {}: ({}, {}, {}) = {}\n", sizeof(a3), carray3_xdim(a3), carray3_ydim(a3), carray3_zdim(a3), carray3_size(a3)); - c_print(1, "a2: {}: ({}, {}) = {}\n", sizeof(a2), carray2_xdim(a2), carray2_ydim(a2), carray2_size(a2)); + printf("a3: %zu: (%zu, %zu, %zu) = %zu\n", sizeof(a3), carray3_xdim(a3), carray3_ydim(a3), carray3_zdim(a3), carray3_size(a3)); + printf("a2: %zu: (%zu, %zu) = %zu\n", sizeof(a2), carray2_xdim(a2), carray2_ydim(a2), carray2_size(a2)); - c_print(1, "{}\n", a1.data[3]); // lookup a1[3] (=10.2f) - c_print(1, "{}\n", *carray2f_at(&a2, 4, 3)); // lookup a2[4][3] (=10.2f) - c_print(1, "{}\n", *carray3f_at(&a3, 5, 4, 3)); // lookup a3[5][4][3] (=10.2f) + printf("%f\n", a1.data[3]); // lookup a1[3] (=10.2f) + printf("%f\n", *carray2f_at(&a2, 4, 3)); // lookup a2[4][3] (=10.2f) + printf("%f\n", *carray3f_at(&a3, 5, 4, 3)); // lookup a3[5][4][3] (=10.2f) c_foreach (i, carray3f, a3) *i.val = 1.0f; - c_print(1, "{:.1f}\n", *carray3f_at(&a3, 29, 19, 9)); + printf("%f\n", *carray3f_at(&a3, 29, 19, 9)); carray2f_del(&a2); // does nothing, since it is a sub-array. carray3f_del(&a3); // also invalidates a2. diff --git a/examples/ex_gaussian.c b/examples/ex_gaussian.c index e60962b4..dc04215c 100644 --- a/examples/ex_gaussian.c +++ b/examples/ex_gaussian.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include @@ -21,7 +21,7 @@ int main() enum {N = 10000000}; const double Mean = -12.0, StdDev = 8.0, Mag = 12000.0 / StdDev; - c_print(1, "Demo of gaussian / normal distribution of {} random samples\n", N); + printf("Demo of gaussian / normal distribution of %d random samples\n", N); // Setup random engine with normal distribution. uint64_t seed = time(NULL); @@ -48,7 +48,7 @@ int main() if (n > 0) { // bar string: take ownership in new str after freeing current. cstr_take(&bar, cstr_with_size(n, '*')); - c_print(1, "{:4} {}\n", i.val->first, bar.str); + printf("%4d %s\n", i.val->first, bar.str); } } // Cleanup diff --git a/examples/heap.c b/examples/heap.c index 17f5fc70..873077fe 100644 --- a/examples/heap.c +++ b/examples/heap.c @@ -3,7 +3,6 @@ #include #include #include -#include using_cvec(f, float); using_cpqueue(f, cvec_f, >); @@ -22,26 +21,26 @@ int main() cvec_f_push_back(&pq, (float) crand_f32(&pcg)*100000); cpqueue_f_make_heap(&pq); - c_print(1, "Built priority queue: {} secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("Built priority queue: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); c_forrange (i, int, M) { - c_print(1, "{} ", *cpqueue_f_top(&pq)); + printf("%g ", *cpqueue_f_top(&pq)); cpqueue_f_pop(&pq); } start = clock(); c_forrange (i, int, M, N) cpqueue_f_pop(&pq); - c_print(1, "\n\npopped PQ: {} secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("\n\npopped PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); pcg = crand_rng32_init(seed); start = clock(); c_forrange (i, int, N) cpqueue_f_push(&pq, (float) crand_f32(&pcg)*100000); - c_print(1, "pushed PQ: {} secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); + printf("pushed PQ: %f secs\n", (clock() - start) / (float) CLOCKS_PER_SEC); c_forrange (i, int, M) { - c_print(1, "{} ", *cpqueue_f_top(&pq)); + printf("%g ", *cpqueue_f_top(&pq)); cpqueue_f_pop(&pq); } puts(""); diff --git a/examples/inits.c b/examples/inits.c index eb480ee6..e358b466 100644 --- a/examples/inits.c +++ b/examples/inits.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -26,7 +26,7 @@ int main(void) cvec_f floats = cvec_inits; c_push_items(&floats, cvec_f, {4.0f, 2.0f, 5.0f, 3.0f, 1.0f}); - c_foreach (i, cvec_f, floats) c_print(1, "{:.1f} ", *i.val); + c_foreach (i, cvec_f, floats) printf("%.1f ", *i.val); puts(""); // CVEC PRIORITY QUEUE @@ -36,7 +36,7 @@ int main(void) // sorted: while (! cpqueue_f_empty(floats)) { - c_print(1, "{:.1f} ", *cpqueue_f_top(&floats)); + printf("%.1f ", *cpqueue_f_top(&floats)); cpqueue_f_pop(&floats); } puts("\n"); @@ -53,7 +53,7 @@ int main(void) }); c_foreach (i, cmap_id, idnames) - c_print(1, "{}: {}\n", i.val->first, i.val->second.str); + printf("%d: %s\n", i.val->first, i.val->second.str); puts(""); cmap_id_del(&idnames); @@ -76,7 +76,7 @@ int main(void) cmap_cnt_emplace(&countries, "Finland", 0).first->second += 20; c_foreach (i, cmap_cnt, countries) - c_print(1, "{}: {}\n", i.val->first.str, i.val->second); + printf("%s: %d\n", i.val->first.str, i.val->second); puts(""); cmap_cnt_del(&countries); @@ -84,12 +84,15 @@ int main(void) cvec_ip pairs1 = cvec_inits; c_push_items(&pairs1, cvec_ip, { - {5, 6}, {3, 4}, {1, 2}, {7, 8}, + {5, 6}, + {3, 4}, + {1, 2}, + {7, 8}, }); cvec_ip_sort(&pairs1); c_foreach (i, cvec_ip, pairs1) - c_print(1, "({} {}) ", i.val->x, i.val->y); + printf("(%d %d) ", i.val->x, i.val->y); puts(""); cvec_ip_del(&pairs1); @@ -97,12 +100,15 @@ int main(void) clist_ip pairs2 = clist_inits; c_push_items(&pairs2, clist_ip, { - {5, 6}, {3, 4}, {1, 2}, {7, 8}, + {5, 6}, + {3, 4}, + {1, 2}, + {7, 8}, }); clist_ip_sort(&pairs2); c_foreach (i, clist_ip, pairs2) - c_print(1, "({} {}) ", i.val->x, i.val->y); + printf("(%d %d) ", i.val->x, i.val->y); puts(""); clist_ip_del(&pairs2); } \ No newline at end of file diff --git a/examples/list.c b/examples/list.c index 81865020..4758b072 100644 --- a/examples/list.c +++ b/examples/list.c @@ -1,8 +1,7 @@ +#include #include #include #include -#include - using_clist(fx, double); int main() { @@ -16,26 +15,26 @@ int main() { c_forrange (i, int, n) clist_fx_push_back(&list, crand_uniform_f64(&eng, &dist)), ++m; double sum = 0.0; - c_print(1, "sumarize {}:\n", m); + printf("sumarize %d:\n", m); c_foreach (i, clist_fx, list) sum += *i.val; - c_print(1, "sum {}\n\n", sum); + printf("sum %f\n\n", sum); k = 0; c_foreach (i, clist_fx, list) - if (++k <= 10) c_print(1, "{:3}: {:16.6f}\n", k, *i.val); else break; + if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break; puts("sort"); clist_fx_sort(&list); // mergesort O(n*log n) puts("sorted"); k = 0; c_foreach (i, clist_fx, list) - if (++k <= 10) c_print(1, "{:3}: {:16.6f}\n", k, *i.val); else break; + if (++k <= 10) printf("%8d: %10f\n", k, *i.val); else break; puts(""); clist_fx_clear(&list); c_push_items(&list, clist_fx, {10, 20, 30, 40, 30, 50}); - c_foreach (i, clist_fx, list) c_print(1, " {}", *i.val); + c_foreach (i, clist_fx, list) printf(" %g", *i.val); puts(""); int removed = clist_fx_remove(&list, 30); @@ -43,13 +42,13 @@ int main() { clist_fx_push_back(&list, 500); clist_fx_push_front(&list, 1964); clist_fx_iter_t it = clist_fx_before_begin(&list); - c_print(1, "Full: "); + printf("Full: "); c_foreach (i, clist_fx, list) - c_print(1, " {}", *i.val); + printf(" %g", *i.val); for (int i=0; i<4; ++i) clist_fx_next(&it); - c_print(1, "\nSubs: "); + printf("\nSubs: "); c_foreach (i, clist_fx, it, clist_fx_end(&list)) - c_print(1, " {}", *i.val); + printf(" %g", *i.val); puts(""); clist_fx_del(&list); } \ No newline at end of file diff --git a/examples/mapmap.c b/examples/mapmap.c index 9e637dde..2ee46e8f 100644 --- a/examples/mapmap.c +++ b/examples/mapmap.c @@ -1,7 +1,7 @@ #include #include -#include +#include using_cmap_str(); using_cmap_strkey(cfg, cmap_str, cmap_str_del); @@ -20,7 +20,7 @@ int main(void) { c_foreach (i, cmap_cfg, config) c_foreach (j, cmap_str, i.val->second) - c_print(1, "{}: {} - {} ({})\n", i.val->first.str, j.val->first.str, j.val->second.str, i.val->second.bucket_count); + printf("%s: %s - %s (%u)\n", i.val->first.str, j.val->first.str, j.val->second.str, i.val->second.bucket_count); cmap_cfg_del(&config); } \ No newline at end of file diff --git a/examples/phonebook.c b/examples/phonebook.c index b929de4e..9eaa2933 100644 --- a/examples/phonebook.c +++ b/examples/phonebook.c @@ -23,14 +23,14 @@ #include #include -#include +#include using_cmap_str(); void print_phone_book(cmap_str phone_book) { c_foreach (i, cmap_str, phone_book) - c_print(1, "{}\t- {}\n", i.val->first.str, i.val->second.str); + printf("%s\t- %s\n", i.val->first.str, i.val->second.str); } int main(int argc, char **argv) diff --git a/examples/prime.c b/examples/prime.c index a21e791a..95e1fd46 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -1,4 +1,4 @@ -#include +#include #include static inline cbitset_t sieveOfEratosthenes(size_t n) @@ -16,23 +16,23 @@ static inline cbitset_t sieveOfEratosthenes(size_t n) } } return pbits; -} +} int main(void) { int n = 100000000; - c_print(1, "computing prime numbers up to {}\n", n); - + printf("computing prime numbers up to %u\n", n); + cbitset_t primes = sieveOfEratosthenes(n); puts("done"); - + size_t np = cbitset_count(primes); - c_print(1, "number of primes: {}\n", np); + printf("number of primes: %zu\n", np); printf("2 "); c_forrange (i, int, 3, 1001, 2) { - if (cbitset_test(primes, i)) c_print(1, "{} ", i); + if (cbitset_test(primes, i)) printf("%d ", i); } puts(""); cbitset_del(&primes); diff --git a/examples/priority.c b/examples/priority.c index 730ae5e3..e4a20da9 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -1,6 +1,7 @@ + +#include #include #include -#include #include #include #include @@ -27,7 +28,7 @@ int main() { // Extract the hundred smallest. c_forrange (100) { - c_print(1, "{} ", *cpqueue_i_top(&heap)); + printf("%zd ", *cpqueue_i_top(&heap)); cpqueue_i_pop(&heap); } cpqueue_i_del(&heap); diff --git a/examples/ptr.c b/examples/ptr.c index 56da4b38..3ffb9292 100644 --- a/examples/ptr.c +++ b/examples/ptr.c @@ -1,5 +1,5 @@ #include -#include +#include #include typedef struct { cstr_t name, last; } Person; @@ -9,7 +9,7 @@ Person* Person_make(Person* p, const char* name, const char* last) { return p; } void Person_del(Person* p) { - c_print(1, "del: {}\n", p->name.str); + printf("del: %s\n", p->name.str); c_del(cstr, &p->name, &p->last); } int Person_compare(const Person* p, const Person* q) { @@ -22,7 +22,7 @@ using_cptr(pe, Person, Person_del, Person_compare); using_cvec(pp, Person*, cptr_pe_del, cptr_pe_compare); int main() { - puts("Vec of Person*:\n--------------"); + puts("Vec of Person *:"); cvec_pp pvec = cvec_pp_init(); cvec_pp_push_back(&pvec, Person_make(c_new(Person), "Joe", "Jordan")); cvec_pp_push_back(&pvec, Person_make(c_new(Person), "Annie", "Aniston")); @@ -30,9 +30,9 @@ int main() { cvec_pp_sort(&pvec); c_foreach (i, cvec_pp, pvec) - c_print(1, "{} {}\n", (*i.val)->name.str, (*i.val)->last.str); + printf("%s %s\n", (*i.val)->name.str, (*i.val)->last.str); - puts("\nVec of Person:\n-------------"); + puts("\nVec of Person:"); cvec_pe vec = cvec_pe_init(); Person tmp; cvec_pe_push_back(&vec, *Person_make(&tmp, "Joe", "Jordan")); @@ -41,7 +41,7 @@ int main() { cvec_pe_sort(&vec); c_foreach (i, cvec_pe, vec) - c_print(1, "{} {}\n", i.val->name.str, i.val->last.str); + printf("%s %s\n", i.val->name.str, i.val->last.str); puts("\nDestroy pvec:"); cvec_pp_del(&pvec); diff --git a/examples/queue.c b/examples/queue.c index ba3d6788..c56214a7 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -1,6 +1,6 @@ #include #include -#include +#include using_clist(i, int); using_cqueue(i, clist_i); // min-heap (increasing values) @@ -18,7 +18,7 @@ int main() { cqueue_i_push(&queue, crand_uniform_i32(&rng, &dist)); // Push or pop on the queue ten million times - c_print(1, "{}\n", n); + printf("%d\n", n); c_forrange (n) { // range uses initial n only. int r = crand_uniform_i32(&rng, &dist); if (r & 1) @@ -26,6 +26,6 @@ int main() { else --n, cqueue_i_pop(&queue); } - c_print(1, "{}, {}\n", n, cqueue_i_size(queue)); + printf("%d, %zu\n", n, cqueue_i_size(queue)); cqueue_i_del(&queue); } diff --git a/examples/random.c b/examples/random.c index 5649a930..7f1be3f5 100644 --- a/examples/random.c +++ b/examples/random.c @@ -1,13 +1,13 @@ #include #include #include -#include +#include int main() { enum {R = 30}; const size_t N = 1000000000; - clock_t difference, before; + clock_t difference, before; uint64_t sum = 0; uint64_t seed = time(NULL); @@ -15,36 +15,36 @@ int main() uint32_t range = crand_i32(&pcg) & ((1u << 28) - 1); crand_uniform_i32_t dist0 = crand_uniform_i32_init(0, range); - c_print(1, "32 uniform: {}\n", dist0.range); - sum = 0; + printf("32 uniform: %u\n", dist0.range); + double fsum = 0; before = clock(); c_forrange (N) { - sum += crand_uniform_i32(&pcg, &dist0); + fsum += (double) crand_uniform_i32(&pcg, &dist0) / dist0.range; } difference = clock() - before; - c_print(1, "{} {}: {} secs\n", N, (double) sum / N / dist0.range, (float) difference / CLOCKS_PER_SEC); + printf("%zu %f: %f secs\n", N, fsum / N, (float) difference / CLOCKS_PER_SEC); pcg = crand_rng32_init(seed); dist0 = crand_uniform_i32_init(0, range); puts("32 unbiased"); - sum = 0; + fsum = 0; before = clock(); c_forrange (N) { - sum += crand_unbiased_i32(&pcg, &dist0); + fsum += (double) crand_unbiased_i32(&pcg, &dist0) / dist0.range; } difference = clock() - before; - c_print(1, "{} {}: {} secs\n", N, (double) sum / N / dist0.range, (float) difference / CLOCKS_PER_SEC); + printf("%zu %f: %f secs\n", N, fsum / N, (float) difference / CLOCKS_PER_SEC); puts("64 uniform"); crand_rng64_t stc = crand_rng64_init(seed); - crand_uniform_i64_t dist1 = crand_uniform_i64_init(0, dist0.range); + crand_uniform_i64_t dist1 = crand_uniform_i64_init(0, N); sum = 0; - before = clock(); + before = clock(); c_forrange (N) { sum += crand_uniform_i64(&stc, &dist1); } difference = clock() - before; - c_print(1, "{} {}: {} secs\n", N, (double) sum / N / dist1.range, (float) difference / CLOCKS_PER_SEC); + printf("%zu %f: %f secs\n", N, (double) sum / N, (float) difference / CLOCKS_PER_SEC); puts("normal distribution"); @@ -57,11 +57,11 @@ int main() sum += n; if (n >= 0 && n < R) ++hist[n]; } - + cstr_t bar = cstr_init(); c_forrange (i, int, R) { cstr_take(&bar, cstr_with_size(hist[i] * 25ull * R / N2, '*')); - c_print(1, "{:3} {}\n", i, bar.str); + printf("%2d %s\n", i, bar.str); } cstr_del(&bar); } \ No newline at end of file diff --git a/examples/rngtest.c b/examples/rngtest.c index 0ca7f79c..df3aa41c 100644 --- a/examples/rngtest.c +++ b/examples/rngtest.c @@ -1,24 +1,23 @@ #include #include #include -#include #ifdef __cplusplus #include #endif -#define NN 300000000 +#define NN 3000000000 int main(void) { clock_t difference, before; uint64_t v; - + crand_rng64_t stc = crand_rng64_init(time(NULL)); crand_uniform_i64_t idist = crand_uniform_i64_init(10, 20); crand_uniform_f64_t fdist = crand_uniform_f64_init(10, 20); - c_forrange (30) c_print(1, "{:02} ", crand_uniform_i64(&stc, &idist)); + c_forrange (30) printf("%02zd ", crand_uniform_i64(&stc, &idist)); puts(""); crand_rng32_t pcg = crand_rng32_init(time(NULL)); @@ -32,7 +31,7 @@ int main(void) v += crand_uniform_i32(&pcg, &i32dist); } difference = clock() - before; - c_print(1, "pcg32: {:.02f}, {}\n", (float) difference / CLOCKS_PER_SEC, v); + printf("pcg32: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v); before = clock(); \ v = 0; @@ -41,15 +40,15 @@ int main(void) v += crand_uniform_i64(&stc, &idist); } difference = clock() - before; - c_print(1, "stc64: {:.02f}, {}\n", (float) difference / CLOCKS_PER_SEC, v); + printf("stc64: %.02f, %zu\n", (float) difference / CLOCKS_PER_SEC, v); - c_forrange (8) c_print(1, "{} ", crand_uniform_i32(&pcg, &i32dist)); + c_forrange (8) printf("%d ", crand_uniform_i32(&pcg, &i32dist)); puts(""); - - c_forrange (8) c_print(1, "{} ", crand_uniform_f32(&pcg, &f32dist)); + + c_forrange (8) printf("%f ", crand_uniform_f32(&pcg, &f32dist)); puts(""); - - c_forrange (8) c_print(1, "{} ", crand_uniform_f64(&stc, &fdist)); + + c_forrange (8) printf("%f ", crand_uniform_f64(&stc, &fdist)); puts(""); } \ No newline at end of file diff --git a/examples/share_ptr.c b/examples/share_ptr.c index 481cfdd6..d851fc58 100644 --- a/examples/share_ptr.c +++ b/examples/share_ptr.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include typedef struct { cstr_t name, last; } Person; @@ -11,7 +11,7 @@ Person* Person_make(Person* p, const char* name, const char* last) { return p; } void Person_del(Person* p) { - c_print(1, "del: {}\n", p->name.str); + printf("del: %s\n", p->name.str); c_del(cstr, &p->name, &p->last); } int Person_compare(const Person* p, const Person* q) { @@ -27,7 +27,8 @@ int main() { clist_pe queue = clist_pe_init(); cvec_pe vec = cvec_pe_init(); - csptr_pe joe = csptr_pe_make((Person) {cstr_from("Joe"), cstr_from("Jordan")}); + Person tmp = {cstr_from("Joe"), cstr_from("Jordan")}; + csptr_pe joe = csptr_pe_make(tmp); clist_pe_push_back(&queue, csptr_pe_share(joe)); cvec_pe_push_back(&vec, csptr_pe_share(joe)); @@ -40,7 +41,7 @@ int main() { cvec_pe_push_back(&vec, csptr_pe_share(p)); // Don't forget to share! } c_foreach (i, clist_pe, queue) - c_print(1, " {}\n", i.val->get->name.str); + printf(" %s\n", i.val->get->name.str); puts("Sort and pop 3:"); clist_pe_sort(&queue); @@ -52,18 +53,18 @@ int main() { puts("Sorted queue:"); c_foreach (i, clist_pe, queue) - c_print(1, " {}\n", i.val->get->name.str); + printf(" %s\n", i.val->get->name.str); puts("Sorted vec:"); c_foreach (i, cvec_pe, vec) - c_print(1, " {}\n", i.val->get->name.str); + printf(" %s\n", i.val->get->name.str); Person lost; Person_make(&lost, "Name 5", "Last 5"); csptr_pe ptmp = {&lost, NULL}; // share pointer without counter - OK. clist_pe_iter_t lit = clist_pe_find(&queue, ptmp); Person_del(&lost); - if (lit.val) c_print(1, "Found: {}\n", lit.val->get->name.str); + if (lit.val) printf("Found: %s\n", lit.val->get->name.str); - c_print(1, "use {}\n", *joe.use_count); + printf("use %ld\n", *joe.use_count); csptr_pe_del(&joe); puts("Destroy queue:"); diff --git a/examples/share_ptr2.c b/examples/share_ptr2.c index 3ef62805..d4b536ac 100644 --- a/examples/share_ptr2.c +++ b/examples/share_ptr2.c @@ -1,12 +1,12 @@ #include #include -#include +#include #include typedef struct { cstr_t name, last; } Person; Person* Person_from(Person* p, cstr_t name, cstr_t last) { - c_print(1, "make {}\n", name.str); + printf("make %s\n", name.str); p->name = name, p->last = last; return p; } @@ -15,7 +15,7 @@ Person* Person_make(Person* p, const char* name, const char* last) { return p; } void Person_del(Person* p) { - c_print(1, "del: {}\n", p->name.str); + printf("del: %s\n", p->name.str); c_del(cstr, &p->name, &p->last); } @@ -36,7 +36,7 @@ int main() { c_try_emplace(&map, cmap_pe, 11, csptr_pe_from(Person_make(c_new(Person), "Hello", "World!"))); c_foreach (i, cmap_pe, map) - c_print(1, " {}: {}\n", i.val->first, i.val->second.get->name.str); + printf(" %d: %s\n", i.val->first, i.val->second.get->name.str); puts("Destroy map:"); cmap_pe_del(&map); diff --git a/examples/stack.c b/examples/stack.c index 428f99a0..f65b9243 100644 --- a/examples/stack.c +++ b/examples/stack.c @@ -1,5 +1,5 @@ -#include +#include #include #include @@ -12,16 +12,16 @@ int main() { cstack_i stack = cstack_i_init(); cstack_c chars = cstack_c_init(); - c_forrange (i, int, 101) + c_forrange (i, int, 101) cstack_i_push(&stack, i*i); - c_print(1, "{}\n", *cstack_i_top(&stack)); + printf("%d\n", *cstack_i_top(&stack)); - c_forrange (i, int, 90) + c_forrange (i, int, 90) cstack_i_pop(&stack); - + c_foreach (i, cstack_i, stack) - c_print(1, " {}", *i.val); + printf(" %d", *i.val); puts(""); - c_print(1, "top: {}\n", *cstack_i_top(&stack)); + printf("top: %d\n", *cstack_i_top(&stack)); } \ No newline at end of file diff --git a/examples/words.c b/examples/words.c index cde1ffa0..7017cebb 100644 --- a/examples/words.c +++ b/examples/words.c @@ -1,5 +1,5 @@ -#include +#include #include #include #include @@ -18,7 +18,7 @@ int main1() }); clist_str_push_back(&lwords, cstr_from_fmt("%f", 123897.0 / 23.0)); c_foreach (w, clist_str, lwords) - c_print(1, "{}\n", w.val->str); + printf("%s\n", w.val->str); puts(""); cvec_str words = cvec_inits; @@ -32,7 +32,7 @@ int main1() cmap_si_emplace(&word_map, w.val->str, 0).first->second += 1; c_foreach (i, cmap_si, word_map) { - c_print(1, "{} occurrences of word '{}'\n", i.val->second, i.val->first.str); + printf("%d occurrences of word '%s'\n", i.val->second, i.val->first.str); } cmap_si_del(&word_map); diff --git a/stc/carray.h b/stc/carray.h index c7b3fd36..fa96da99 100644 --- a/stc/carray.h +++ b/stc/carray.h @@ -29,8 +29,8 @@ /* Multi-dimensional generic array allocated as one block of heap-memory. // demo: +#include #include -#include using_carray(f, float); int main() @@ -38,8 +38,8 @@ int main() carray3f a3 = carray3f_init(30, 20, 10, 0.f); *carray3f_at(a3, 5, 4, 3) = 10.2f; // a3[5][4][3] carray2f a2 = carray3f_at1(a3, 5); // sub-array reference: a2 = a3[5] - c_printf(1, "{}\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f) - c_printf(1, "{}\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array. + printf("%g\n", *carray2f_at(a2, 4, 3)); // lookup a2[4][3] (=10.2f) + printf("%g\n", *carray3f_at(a3, 5, 4, 3)); // same data location, via a3 array. carray2f_del(&a2); // does nothing, since it is a sub-array. carray3f_del(&a3); // destroy a3, invalidates a2. -- cgit v1.2.3