From c5abb5b806ddc3eedde2e6bcd31eef78c36edf33 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Tue, 3 Jan 2023 10:37:44 +0100 Subject: Fix compilation error in utf8code.c due to predeclaring a static array with unspecified size. --- misc/examples/sort.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'misc') diff --git a/misc/examples/sort.c b/misc/examples/sort.c index 65ae7359..ace1a6a4 100644 --- a/misc/examples/sort.c +++ b/misc/examples/sort.c @@ -1,39 +1,45 @@ -#include #include #include -#define i_val int +#include #include -#include + +typedef float Elem; +#define fmt_Elem "%g" #ifdef __cplusplus -#include + #include +#else + #define i_val Elem + #include #endif -int testsort(csortval_int *a, size_t size, const char *desc) { +int testsort(Elem *a, size_t size, const char *desc) { clock_t t = clock(); #ifdef __cplusplus printf("std::sort: "); std::sort(a, a + size); #else printf("csort: "); - csort_int(a, size); + csort_Elem(a, size); #endif t = clock() - t; - printf("%s: %d elements sorted in %.3fms\n", + printf("%s: %d elements sorted in %.2f ms\n", desc, (int)size, t*1000.0/CLOCKS_PER_SEC); return 0; } int main(int argc, char *argv[]) { size_t i, size = argc > 1 ? strtoull(argv[1], NULL, 0) : 10000000; - csortval_int *a = (csortval_int*)malloc(sizeof(*a) * size); + Elem *a = (Elem*)malloc(sizeof(*a) * size); if (a == NULL) return -1; for (i = 0; i < size; i++) a[i] = crandom() & ((1U << 28) - 1); + testsort(a, size, "random"); - for (i = 0; i < 20; i++) printf(" %d", a[i]); + for (i = 0; i < 20; i++) + printf(" " fmt_Elem, a[i]); puts(""); testsort(a, size, "sorted"); -- cgit v1.2.3