summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-03 10:37:44 +0100
committerTyge Løvset <[email protected]>2023-01-03 10:37:44 +0100
commitc5abb5b806ddc3eedde2e6bcd31eef78c36edf33 (patch)
tree70198361b1133d7c6eb930c998eaaf6888d13309
parent16e004c62f8d8d502152a85b2ffd384a1c91a470 (diff)
downloadSTC-modified-c5abb5b806ddc3eedde2e6bcd31eef78c36edf33.tar.gz
STC-modified-c5abb5b806ddc3eedde2e6bcd31eef78c36edf33.zip
Fix compilation error in utf8code.c due to predeclaring a static array with unspecified size.
-rw-r--r--include/stc/utf8.h1
-rw-r--r--misc/examples/sort.c24
-rw-r--r--src/utf8code.c12
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 <stdio.h>
#include <time.h>
#include <stdlib.h>
-#define i_val int
+#include <stdio.h>
#include <stc/crandom.h>
-#include <stc/algo/csort.h>
+
+typedef float Elem;
+#define fmt_Elem "%g"
#ifdef __cplusplus
-#include <algorithm>
+ #include <algorithm>
+#else
+ #define i_val Elem
+ #include <stc/algo/csort.h>
#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<unicode_groups[group].nr16; ++j) {
@@ -163,6 +161,8 @@ bool utf8_isword(uint32_t c) {
utf8_isgroup(U8G_Nd, c) || utf8_isgroup(U8G_Pc, c) || utf8_isgroup(U8G_Nl, c);
}
+/* The tables below are extracted from the RE2 library */
+
static const URange16 Cc_range16[] = { // Control
{ 0, 31 },
{ 127, 159 },
@@ -328,9 +328,9 @@ static const URange16 Zs_range16[] = { // Space separator
};
#define UNI_ENTRY(Code) \
- { #Code, Code##_range16, sizeof(Code##_range16)/(2*2) }
+ { Code##_range16, sizeof(Code##_range16)/sizeof(URange16) }
-static const UGroup unicode_groups[] = {
+static const UGroup unicode_groups[U8G_SIZE] = {
[U8G_Cc] = UNI_ENTRY(Cc),
[U8G_Lt] = UNI_ENTRY(Lt),
[U8G_Nd] = UNI_ENTRY(Nd),
@@ -345,6 +345,4 @@ static const UGroup unicode_groups[] = {
[U8G_Zs] = UNI_ENTRY(Zs),
};
-static const int num_unicode_groups = sizeof unicode_groups / sizeof unicode_groups[0];
-
#endif