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. --- include/stc/utf8.h | 1 + misc/examples/sort.c | 24 +++++++++++++++--------- src/utf8code.c | 12 +++++------- 3 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/stc/utf8.h b/include/stc/utf8.h index 3246e654..4e38a5c8 100644 --- a/include/stc/utf8.h +++ b/include/stc/utf8.h @@ -9,6 +9,7 @@ enum { U8G_Cc, U8G_Lt, U8G_Nd, U8G_Nl, U8G_Pc, U8G_Pd, U8G_Pf, U8G_Pi, U8G_Sc, U8G_Zl, U8G_Zp, U8G_Zs, + U8G_SIZE }; extern bool utf8_isgroup(int group, uint32_t c); extern bool utf8_isblank(uint32_t c); 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"); diff --git a/src/utf8code.c b/src/utf8code.c index 4b657cc4..c4866b78 100644 --- a/src/utf8code.c +++ b/src/utf8code.c @@ -118,13 +118,11 @@ typedef struct { } URange16; typedef struct { - const char *name; const URange16 *r16; int nr16; } UGroup; -static const UGroup unicode_groups[]; -static const int num_unicode_groups; +static const UGroup unicode_groups[U8G_SIZE]; bool utf8_isgroup(int group, uint32_t c) { for (int j=0; j