diff options
| author | Tyge Løvset <[email protected]> | 2022-10-14 16:02:25 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-10-14 16:02:25 +0200 |
| commit | d26fd02b70b9f091c2bcfa350e420f74c1f023f8 (patch) | |
| tree | 7ca2902ee839cb1ce7bfc3333f6ead2e4ea39ef2 | |
| parent | 54c08dc031c622e78dc134353690ed359b9173d8 (diff) | |
| download | STC-modified-d26fd02b70b9f091c2bcfa350e420f74c1f023f8.tar.gz STC-modified-d26fd02b70b9f091c2bcfa350e420f74c1f023f8.zip | |
Replaced PRIuMAX with new c_zu macro in examples. "%zu" is not supported by mingw64 and PRIuMAX is not a replacement for "zu".
| -rw-r--r-- | benchmarks/misc/rust_cmap.c | 10 | ||||
| -rw-r--r-- | benchmarks/shootout_hashmaps.cpp | 12 | ||||
| -rw-r--r-- | docs/cbits_api.md | 6 | ||||
| -rw-r--r-- | docs/cstr_api.md | 2 | ||||
| -rw-r--r-- | examples/birthday.c | 4 | ||||
| -rw-r--r-- | examples/bits.c | 12 | ||||
| -rw-r--r-- | examples/bits2.c | 4 | ||||
| -rw-r--r-- | examples/books.c | 2 | ||||
| -rw-r--r-- | examples/box2.c | 12 | ||||
| -rw-r--r-- | examples/complex.c | 2 | ||||
| -rw-r--r-- | examples/csmap_erase.c | 4 | ||||
| -rw-r--r-- | examples/csmap_find.c | 2 | ||||
| -rw-r--r-- | examples/cstr_match.c | 4 | ||||
| -rw-r--r-- | examples/demos.c | 10 | ||||
| -rw-r--r-- | examples/new_queue.c | 4 | ||||
| -rw-r--r-- | examples/prime.c | 4 | ||||
| -rw-r--r-- | examples/priority.c | 2 | ||||
| -rw-r--r-- | examples/queue.c | 2 | ||||
| -rw-r--r-- | examples/random.c | 6 | ||||
| -rw-r--r-- | examples/sso_map.c | 2 | ||||
| -rw-r--r-- | include/stc/carc.h | 2 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 6 |
22 files changed, 60 insertions, 54 deletions
diff --git a/benchmarks/misc/rust_cmap.c b/benchmarks/misc/rust_cmap.c index e5d85b1c..20ed87be 100644 --- a/benchmarks/misc/rust_cmap.c +++ b/benchmarks/misc/rust_cmap.c @@ -29,7 +29,7 @@ int main() ms = CLOCKS_PER_SEC/1000; cmap_u64_max_load_factor(&m, 0.8); cmap_u64_reserve(&m, n); - printf("STC cmap n = %" PRIuMAX ", mask = 0x%" PRIxMAX "\n", n, mask); + printf("STC cmap n = %" c_zu ", mask = 0x%" PRIxMAX "\n", n, mask); uint64_t rng[3] = {1872361123, 123879177, 87739234}, sum; clock_t now = clock(); @@ -37,17 +37,17 @@ int main() uint64_t key = romu_trio(rng) & mask; cmap_u64_insert(&m, key, 0).ref->second += 1; } - printf("insert : %" PRIuMAX "ms \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(&m)); + printf("insert : %" c_zu "ms \tsize : %" c_zu "\n", (clock() - now)/ms, cmap_u64_size(&m)); now = clock(); sum = 0; c_forloop (key, mask + 1) { sum += cmap_u64_contains(&m, key); } - printf("lookup : %" PRIuMAX "ms \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum); + printf("lookup : %" c_zu "ms \tsum : %" c_zu "\n", (clock() - now)/ms, sum); now = clock(); sum = 0; c_foreach (i, cmap_u64, m) { sum += i.ref->second; } - printf("iterate : %" PRIuMAX "ms \tsum : %" PRIuMAX "\n", (clock() - now)/ms, sum); + printf("iterate : %" c_zu "ms \tsum : %" c_zu "\n", (clock() - now)/ms, sum); uint64_t rng2[3] = {1872361123, 123879177, 87739234}; now = clock(); @@ -55,7 +55,7 @@ int main() uint64_t key = romu_trio(rng2) & mask; cmap_u64_erase(&m, key); } - printf("remove : %" PRIuMAX "ms \tsize : %" PRIuMAX "\n", (clock() - now)/ms, cmap_u64_size(&m)); + printf("remove : %" c_zu "ms \tsize : %" c_zu "\n", (clock() - now)/ms, cmap_u64_size(&m)); printf("press a key:\n"); getchar(); } } diff --git a/benchmarks/shootout_hashmaps.cpp b/benchmarks/shootout_hashmaps.cpp index 334eff64..cc1778d1 100644 --- a/benchmarks/shootout_hashmaps.cpp +++ b/benchmarks/shootout_hashmaps.cpp @@ -184,7 +184,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) sum += ++ M##_PUT(X, RAND(keybits), i); \ } \ difference = clock() - before; \ - printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8" PRIuMAX ", sum: %" PRIuMAX "\n", \ + printf(#M ": time: %5.03f, size: %" c_zu ", buckets: %8" c_zu ", sum: %" c_zu "\n", \ (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), sum); \ M##_DTOR(X); \ } @@ -199,7 +199,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) for (size_t i = 0; i < n; ++i) \ erased += M##_ERASE(X, i); \ difference = clock() - before; \ - printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8" PRIuMAX ", erased %" PRIuMAX "\n", \ + printf(#M ": time: %5.03f, size: %" c_zu ", buckets: %8" c_zu ", erased %" c_zu "\n", \ (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \ M##_DTOR(X); \ } @@ -217,7 +217,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) for (size_t i = 0; i < n; ++i) \ erased += M##_ERASE(X, RAND(keybits)); \ difference = clock() - before; \ - printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8" PRIuMAX ", erased %" PRIuMAX "\n", \ + printf(#M ": time: %5.03f, size: %" c_zu ", buckets: %8" c_zu ", erased %" c_zu "\n", \ (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), erased); \ M##_DTOR(X); \ } @@ -235,7 +235,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) for (size_t k=0; k < rep; k++) M##_FOR (X, it) \ sum += M##_ITEM(X, it); \ difference = clock() - before; \ - printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8" PRIuMAX ", repeats: %" PRIuMAX ", sum: %" PRIuMAX "\n", \ + printf(#M ": time: %5.03f, size: %" c_zu ", buckets: %8" c_zu ", repeats: %" c_zu ", sum: %" c_zu "\n", \ (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), rep, sum); \ M##_DTOR(X); \ } @@ -257,7 +257,7 @@ KHASH_MAP_INIT_INT64(ii, IValue) for (size_t i = 0; i < x; ++i) \ found += M##_FIND(X, RAND(keybits)); \ difference = clock() - before; \ - printf(#M ": time: %5.03f, size: %" PRIuMAX ", buckets: %8" PRIuMAX ", lookups: %" PRIuMAX ", found: %" PRIuMAX "\n", \ + printf(#M ": time: %5.03f, size: %" c_zu ", buckets: %8" c_zu ", lookups: %" c_zu ", found: %" c_zu "\n", \ (float) difference / CLOCKS_PER_SEC, (size_t) M##_SIZE(X), (size_t) M##_BUCKETS(X), x*2, found); \ M##_DTOR(X); \ } @@ -299,7 +299,7 @@ int main(int argc, char* argv[]) "UMAP = std::unordered_map\n\n"); printf("Usage %s [n-million=%d key-bits=%d]\n", argv[0], DEFAULT_N_MILL, DEFAULT_KEYBITS); - printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %" PRIuMAX ":\n", n_mill, keybits, seed); + printf("N-base = %d. Random keys are in range [0, 2^%d). Seed = %" c_zu ":\n", n_mill, keybits, seed); printf("\nT1: Insert/update random keys:\n"); RUN_TEST(1) diff --git a/docs/cbits_api.md b/docs/cbits_api.md index 269db9b3..51c89f21 100644 --- a/docs/cbits_api.md +++ b/docs/cbits_api.md @@ -91,18 +91,18 @@ cbits sieveOfEratosthenes(size_t n) int main(void) { size_t n = 100000000; - printf("computing prime numbers up to %" PRIuMAX "\n", n); + printf("computing prime numbers up to %" c_zu "\n", n); clock_t t1 = clock(); cbits primes = sieveOfEratosthenes(n + 1); size_t nprimes = cbits_count(&primes); clock_t t2 = clock(); - printf("number of primes: %" PRIuMAX ", time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC); + printf("number of primes: %" c_zu ", time: %f\n", nprimes, (float)(t2 - t1)/CLOCKS_PER_SEC); printf(" 2"); for (size_t i = 3; i < 1000; i += 2) - if (cbits_test(&primes, i>>1)) printf(" %" PRIuMAX "", i); + if (cbits_test(&primes, i>>1)) printf(" %" c_zu, i); puts(""); cbits_drop(&primes); diff --git a/docs/cstr_api.md b/docs/cstr_api.md index 439faca7..ceeeac2a 100644 --- a/docs/cstr_api.md +++ b/docs/cstr_api.md @@ -161,7 +161,7 @@ char* c_strnstrn(const char* str, const char* search, size_t slen, size_t int main() { cstr s0 = cstr_new("Initialization without using strlen()."); - printf("%s\nLength: %" PRIuMAX "\n\n", cstr_str(&s0), cstr_size(&s0)); + printf("%s\nLength: %" c_zu "\n\n", cstr_str(&s0), cstr_size(&s0)); cstr s1 = cstr_new("one-nine-three-seven-five."); printf("%s\n", cstr_str(&s1)); diff --git a/examples/birthday.c b/examples/birthday.c index 8b23f7ab..ce7a7edb 100644 --- a/examples/birthday.c +++ b/examples/birthday.c @@ -24,7 +24,7 @@ static void test_repeats(void) c_forloop (i, N) { uint64_t k = stc64_rand(&rng) & mask; int v = cmap_ic_insert(&m, k, 0).ref->second += 1; - if (v > 1) printf("repeated value %" PRIuMAX " (%d) at 2^%d\n", k, v, (int) log2((double) i)); + if (v > 1) printf("repeated value %" c_zu " (%d) at 2^%d\n", k, v, (int) log2((double) i)); } } } @@ -52,7 +52,7 @@ void test_distribution(void) sum /= map.size; c_foreach (i, cmap_x, map) { - printf("%4u: %" PRIuMAX " - %" PRIuMAX ": %11.8f\n", i.ref->first, i.ref->second, sum, (1 - (double) i.ref->second / sum)); + printf("%4u: %" c_zu " - %" c_zu ": %11.8f\n", i.ref->first, i.ref->second, sum, (1 - (double) i.ref->second / sum)); } } } diff --git a/examples/bits.c b/examples/bits.c index c89ad7d3..505be497 100644 --- a/examples/bits.c +++ b/examples/bits.c @@ -4,11 +4,11 @@ int main() { c_with (cbits set = cbits_with_size(23, true), cbits_drop(&set)) { - printf("count %" PRIuMAX ", %" PRIuMAX "\n", cbits_count(&set), cbits_size(&set)); + printf("count %" c_zu ", %" c_zu "\n", cbits_count(&set), cbits_size(&set)); cbits s1 = cbits_from("1110100110111"); char buf[256]; cbits_to_str(&s1, buf, 0, -1); - printf("buf: %s: %" PRIuMAX "\n", buf, cbits_count(&s1)); + printf("buf: %s: %" c_zu "\n", buf, cbits_count(&s1)); cbits_drop(&s1); cbits_reset(&set, 9); @@ -16,7 +16,7 @@ int main() c_autobuf (str, char, cbits_size(&set) + 1) printf(" str: %s\n", cbits_to_str(&set, str, 0, -1)); - printf("%4" PRIuMAX ": ", cbits_size(&set)); + printf("%4" c_zu ": ", cbits_size(&set)); c_forloop (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); @@ -26,12 +26,12 @@ int main() cbits_resize(&set, 93, false); cbits_resize(&set, 102, true); cbits_set_value(&set, 99, false); - printf("%4" PRIuMAX ": ", cbits_size(&set)); + printf("%4" c_zu ": ", cbits_size(&set)); c_forloop (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts("\nIterate:"); - printf("%4" PRIuMAX ": ", cbits_size(&set)); + printf("%4" c_zu ": ", cbits_size(&set)); c_forloop (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); @@ -53,7 +53,7 @@ int main() puts(""); cbits_set_all(&set, false); - printf("%4" PRIuMAX ": ", cbits_size(&set)); + printf("%4" c_zu ": ", cbits_size(&set)); c_forloop (i, cbits_size(&set)) printf("%d", cbits_test(&set, i)); puts(""); diff --git a/examples/bits2.c b/examples/bits2.c index 0161376b..c2c1f6be 100644 --- a/examples/bits2.c +++ b/examples/bits2.c @@ -9,10 +9,10 @@ int main() { Bits s1 = Bits_from("1110100110111"); - printf("size %" PRIuMAX "\n", Bits_size(&s1)); + printf("size %" c_zu "\n", Bits_size(&s1)); char buf[256]; Bits_to_str(&s1, buf, 0, -1); - printf("buf: %s: count=%" PRIuMAX "\n", buf, Bits_count(&s1)); + printf("buf: %s: count=%" c_zu "\n", buf, Bits_count(&s1)); Bits_reset(&s1, 8); c_autobuf (str, char, Bits_size(&s1) + 1) diff --git a/examples/books.c b/examples/books.c index 90d2d529..e1962a92 100644 --- a/examples/books.c +++ b/examples/books.c @@ -32,7 +32,7 @@ int main() // When collections store owned values (String), they can still be // queried using references (&str). if (cmap_str_contains(&book_reviews, "Les Misérables")) { - printf("We've got %" PRIuMAX " reviews, but Les Misérables ain't one.", + printf("We've got %" c_zu " reviews, but Les Misérables ain't one.", cmap_str_size(&book_reviews)); } diff --git a/examples/box2.c b/examples/box2.c index 28b4acff..13dc8c26 100644 --- a/examples/box2.c +++ b/examples/box2.c @@ -64,22 +64,22 @@ int main(void) { // Double indirection box_in_a_box = cbox_BoxPoint_from(boxed_origin()); - printf("Point occupies %" PRIuMAX " bytes on the stack\n", + printf("Point occupies %" c_zu " bytes on the stack\n", sizeof(point)); - printf("Rectangle occupies %" PRIuMAX " bytes on the stack\n", + printf("Rectangle occupies %" c_zu " bytes on the stack\n", sizeof(rectangle)); // box size == pointer size - printf("Boxed point occupies %" PRIuMAX " bytes on the stack\n", + printf("Boxed point occupies %" c_zu " bytes on the stack\n", sizeof(boxed_point)); - printf("Boxed rectangle occupies %" PRIuMAX " bytes on the stack\n", + printf("Boxed rectangle occupies %" c_zu " bytes on the stack\n", sizeof(boxed_rectangle)); - printf("Boxed box occupies %" PRIuMAX " bytes on the stack\n", + printf("Boxed box occupies %" c_zu " bytes on the stack\n", sizeof(box_in_a_box)); // Copy the data contained in `boxed_point` into `unboxed_point` Point unboxed_point = *boxed_point.get; - printf("Unboxed point occupies %" PRIuMAX " bytes on the stack\n", + printf("Unboxed point occupies %" c_zu " bytes on the stack\n", sizeof(unboxed_point)); } } diff --git a/examples/complex.c b/examples/complex.c index 59683fac..5e3f53a9 100644 --- a/examples/complex.c +++ b/examples/complex.c @@ -40,7 +40,7 @@ int main() { // Put in some data in stack array stack.data[x] = 3.1415927f; - printf("stack size: %" PRIuMAX "\n", FloatStack_size(&stack)); + printf("stack size: %" c_zu "\n", FloatStack_size(&stack)); StackList list = StackList_init(); StackList_push_back(&list, stack); diff --git a/examples/csmap_erase.c b/examples/csmap_erase.c index 318d74b4..d05c32fe 100644 --- a/examples/csmap_erase.c +++ b/examples/csmap_erase.c @@ -12,7 +12,7 @@ void printmap(mymap m) { c_foreach (elem, mymap, m) printf(" [%d, %s]", elem.ref->first, cstr_str(&elem.ref->second)); - printf("\nsize() == %" PRIuMAX "\n\n", mymap_size(&m)); + printf("\nsize() == %" c_zu "\n\n", mymap_size(&m)); } int main() @@ -77,7 +77,7 @@ int main() // The 3rd member function removes elements with a given Key size_t count = mymap_erase(&m3, 2); // The 3rd member function also returns the number of elements removed - printf("The number of elements removed from m3 is: %" PRIuMAX "\n", count); + printf("The number of elements removed from m3 is: %" c_zu "\n", count); puts("After the element with a key of 2 is deleted, the map m3 is:"); printmap(m3); } diff --git a/examples/csmap_find.c b/examples/csmap_find.c index e281a431..9287a89b 100644 --- a/examples/csmap_find.c +++ b/examples/csmap_find.c @@ -18,7 +18,7 @@ void print_elem(csmap_istr_raw p) { #define using_print_collection(CX) \ void print_collection_##CX(const CX* t) { \ - printf("%" PRIuMAX " elements: ", CX##_size(t)); \ + printf("%" c_zu " elements: ", CX##_size(t)); \ \ c_foreach (p, CX, *t) { \ print_elem(CX##_value_toraw(p.ref)); \ diff --git a/examples/cstr_match.c b/examples/cstr_match.c index 614af490..a991278c 100644 --- a/examples/cstr_match.c +++ b/examples/cstr_match.c @@ -6,7 +6,7 @@ int main() { c_with (cstr ss = cstr_new("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) { size_t pos = cstr_find_at(&ss, 0, "brown"); - printf("%" PRIuMAX " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : cstr_str(&ss) + pos); + printf("%" c_zu " [%s]\n", pos, pos == cstr_npos ? "<NULL>" : cstr_str(&ss) + pos); printf("equals: %d\n", cstr_equals(&ss, "The quick brown fox jumps over the lazy dog.JPG")); printf("contains: %d\n", cstr_contains(&ss, "umps ove")); printf("starts_with: %d\n", cstr_starts_with(&ss, "The quick brown")); @@ -16,7 +16,7 @@ int main() cstr s1 = cstr_new("hell😀 w😀rl🐨"); csview ch1 = cstr_u8_chr(&s1, 7); csview ch2 = cstr_u8_chr(&s1, 10); - printf("%s\nsize: %" PRIuMAX ", %" PRIuMAX "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1)); + printf("%s\nsize: %" c_zu ", %" c_zu "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1)); printf("ch1: %.*s\n", c_ARGsv(ch1)); printf("ch2: %.*s\n", c_ARGsv(ch2)); } diff --git a/examples/demos.c b/examples/demos.c index d7097961..3f0125fd 100644 --- a/examples/demos.c +++ b/examples/demos.c @@ -41,14 +41,14 @@ void vectordemo1() for (size_t i = 10; i <= 100; i += 10) cvec_ix_push_back(&bignums, i * i); - printf("erase - %d: %" PRIuMAX "\n", 3, bignums.data[3]); + printf("erase - %d: %" c_zu "\n", 3, bignums.data[3]); cvec_ix_erase_n(&bignums, 3, 1); // erase index 3 cvec_ix_pop_back(&bignums); // erase the last cvec_ix_erase_n(&bignums, 0, 1); // erase the first for (size_t i = 0; i < cvec_ix_size(&bignums); ++i) { - printf("%" PRIuMAX ": %" PRIuMAX "\n", i, bignums.data[i]); + printf("%" c_zu ": %" c_zu "\n", i, bignums.data[i]); } } } @@ -175,11 +175,11 @@ void mapdemo3() cmap_str_iter it = cmap_str_find(&table, "Make"); c_foreach (i, cmap_str, table) printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second)); - printf("size %" PRIuMAX ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second)); + printf("size %" c_zu ": remove: Make: %s\n", cmap_str_size(&table), cstr_str(&it.ref->second)); //cmap_str_erase(&table, "Make"); cmap_str_erase_at(&table, it); - printf("size %" PRIuMAX "\n", cmap_str_size(&table)); + printf("size %" c_zu "\n", cmap_str_size(&table)); c_foreach (i, cmap_str, table) printf("entry: %s: %s\n", cstr_str(&i.ref->first), cstr_str(&i.ref->second)); cmap_str_drop(&table); // frees key and value cstrs, and hash table. @@ -199,7 +199,7 @@ void arraydemo1() float **arr2 = arr3.data[5]; float *arr1 = arr3.data[5][4]; - printf("arr3: %" PRIuMAX ": (%" PRIuMAX ", %" PRIuMAX ", %" PRIuMAX ") = %" PRIuMAX "\n", sizeof(arr3), + printf("arr3: %" c_zu ": (%" c_zu ", %" c_zu ", %" c_zu ") = %" c_zu "\n", sizeof(arr3), arr3.xdim, arr3.ydim, arr3.zdim, carr3_f_size(&arr3)); printf("%g\n", arr1[3]); // = 10.2 diff --git a/examples/new_queue.c b/examples/new_queue.c index eebf3493..9445e040 100644 --- a/examples/new_queue.c +++ b/examples/new_queue.c @@ -32,7 +32,7 @@ int main() { IQ_push(&Q, stc64_uniform(&rng, &dist)); // Push or pop on the queue 50 million times - printf("befor: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q)); + printf("befor: size %" c_zu ", capacity %" c_zu "\n", IQ_size(&Q), IQ_capacity(&Q)); c_forloop (n) { int r = stc64_uniform(&rng, &dist); if (r & 3) @@ -40,6 +40,6 @@ int main() { else IQ_pop(&Q); } - printf("after: size %" PRIuMAX ", capacity %" PRIuMAX "\n", IQ_size(&Q), IQ_capacity(&Q)); + printf("after: size %" c_zu ", capacity %" c_zu "\n", IQ_size(&Q), IQ_capacity(&Q)); } } diff --git a/examples/prime.c b/examples/prime.c index 3f0c4f6e..851ee40b 100644 --- a/examples/prime.c +++ b/examples/prime.c @@ -25,7 +25,7 @@ cbits sieveOfEratosthenes(size_t n) int main(void) { size_t n = 1000000000; - printf("computing prime numbers up to %" PRIuMAX "\n", n); + printf("computing prime numbers up to %" c_zu "\n", n); clock_t t1 = clock(); c_with (cbits primes = sieveOfEratosthenes(n + 1), cbits_drop(&primes)) { @@ -33,7 +33,7 @@ int main(void) size_t np = cbits_count(&primes); clock_t t2 = clock(); - printf("number of primes: %" PRIuMAX ", time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC); + printf("number of primes: %" c_zu ", time: %f\n", np, (t2 - t1) / (float)CLOCKS_PER_SEC); puts("Show all the primes in the range [2, 1000):"); printf("2"); c_forloop (i, 3, 1000, 2) diff --git a/examples/priority.c b/examples/priority.c index 452ed9d4..d82c889a 100644 --- a/examples/priority.c +++ b/examples/priority.c @@ -15,7 +15,7 @@ int main() { c_auto (cpque_i, heap) { // Push ten million random numbers to priority queue - printf("Push %" PRIuMAX " numbers\n", N); + printf("Push %" c_zu " numbers\n", N); c_forloop (N) cpque_i_push(&heap, stc64_uniform(&rng, &dist)); diff --git a/examples/queue.c b/examples/queue.c index 7be25367..cf75615c 100644 --- a/examples/queue.c +++ b/examples/queue.c @@ -26,6 +26,6 @@ int main() { else --n, cqueue_i_pop(&queue); } - printf("%d, %" PRIuMAX "\n", n, cqueue_i_size(&queue)); + printf("%d, %" c_zu "\n", n, cqueue_i_size(&queue)); } } diff --git a/examples/random.c b/examples/random.c index 99001a1a..638f2a9f 100644 --- a/examples/random.c +++ b/examples/random.c @@ -18,7 +18,7 @@ int main() sum += (uint32_t) stc64_rand(&rng); } diff = clock() - before; - printf("full range\t\t: %f secs, %" PRIuMAX ", avg: %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); + printf("full range\t\t: %f secs, %" c_zu ", avg: %f\n", (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); stc64_uniform_t dist1 = stc64_uniform_new(0, range); rng = stc64_new(seed); @@ -28,7 +28,7 @@ int main() sum += stc64_uniform(&rng, &dist1); // unbiased } diff = clock() - before; - printf("unbiased 0-%" PRIuMAX "\t: %f secs, %" PRIuMAX ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); + printf("unbiased 0-%" c_zu "\t: %f secs, %" c_zu ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); sum = 0; rng = stc64_new(seed); @@ -37,6 +37,6 @@ int main() sum += stc64_rand(&rng) % (range + 1); // biased } diff = clock() - before; - printf("biased 0-%" PRIuMAX " \t: %f secs, %" PRIuMAX ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); + printf("biased 0-%" c_zu " \t: %f secs, %" c_zu ", avg: %f\n", range, (float) diff / CLOCKS_PER_SEC, N, (double) sum / N); } diff --git a/examples/sso_map.c b/examples/sso_map.c index 43bcb40b..a7ee5bb5 100644 --- a/examples/sso_map.c +++ b/examples/sso_map.c @@ -10,7 +10,7 @@ int main() cmap_str_emplace(&m, "Test long ", "This is a longer string."); c_forpair (k, v, cmap_str, m) - printf("%s: '%s' Len=%" PRIuMAX ", Is long: %s\n", + printf("%s: '%s' Len=%" c_zu ", Is long: %s\n", cstr_str(_.k), cstr_str(_.v), cstr_size(_.v), cstr_is_long(_.v)?"true":"false"); } diff --git a/include/stc/carc.h b/include/stc/carc.h index d0adcceb..f0ab651b 100644 --- a/include/stc/carc.h +++ b/include/stc/carc.h @@ -43,7 +43,7 @@ int main() { ArcPers p = ArcPers_from(Person_new("John", "Smiths")); ArcPers q = ArcPers_clone(p); // share the pointer - printf("%s %s. uses: %" PRIuMAX "\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count); + printf("%s %s. uses: %" c_zu "\n", cstr_str(&q.get->name), cstr_str(&q.get->last), *q.use_count); c_drop(ArcPers, &p, &q); } */ diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index e3406727..394964c0 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -30,6 +30,12 @@ #include <string.h> #include <assert.h> +#if SIZE_MAX == UINT32_MAX +# define c_zu PRIu32 +#elif SIZE_MAX == UINT64_MAX +# define c_zu PRIu64 +#endif + #if defined(_MSC_VER) # pragma warning(disable: 4116 4996) // unnamed type definition in parentheses # define STC_FORCE_INLINE static __forceinline |
