summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-05-01 10:00:07 +0200
committerTyge Løvset <[email protected]>2023-05-01 10:02:12 +0200
commitf916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe (patch)
tree22283c2d74f2cac441ce04b3106e144f440b8137 /misc/examples
parent49e7d9cc0a888b0b19aa4e737d55a2bc33bec824 (diff)
downloadSTC-modified-f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe.tar.gz
STC-modified-f916573e2b3652d9b3f6fb82aadd5f2cfb3ce2fe.zip
Remove warnings when using -Wextra.
Diffstat (limited to 'misc/examples')
-rw-r--r--misc/examples/birthday.c4
-rw-r--r--misc/examples/complex.c2
-rw-r--r--misc/examples/gauss2.c2
-rw-r--r--misc/examples/inits.c2
-rwxr-xr-xmisc/examples/make.sh4
-rw-r--r--misc/examples/new_list.c2
-rw-r--r--misc/examples/new_map.c6
-rw-r--r--misc/examples/new_pque.c2
-rw-r--r--misc/examples/new_queue.c2
-rw-r--r--misc/examples/new_smap.c2
-rw-r--r--misc/examples/new_vec.c4
-rw-r--r--misc/examples/prime.c12
-rw-r--r--misc/examples/random.c14
-rw-r--r--misc/examples/regex_match.c2
-rw-r--r--misc/examples/shape.c8
15 files changed, 34 insertions, 34 deletions
diff --git a/misc/examples/birthday.c b/misc/examples/birthday.c
index c301128a..2820c42f 100644
--- a/misc/examples/birthday.c
+++ b/misc/examples/birthday.c
@@ -13,8 +13,8 @@ static uint64_t seed = 12345;
static void test_repeats(void)
{
enum {BITS = 46, BITS_TEST = BITS/2 + 2};
- const static uint64_t N = 1ull << BITS_TEST;
- const static uint64_t mask = (1ull << BITS) - 1;
+ static const uint64_t N = 1ull << BITS_TEST;
+ static const uint64_t mask = (1ull << BITS) - 1;
printf("birthday paradox: value range: 2^%d, testing repeats of 2^%d values\n", BITS, BITS_TEST);
crand_t rng = crand_init(seed);
diff --git a/misc/examples/complex.c b/misc/examples/complex.c
index 7dde981d..c730db33 100644
--- a/misc/examples/complex.c
+++ b/misc/examples/complex.c
@@ -44,7 +44,7 @@ int main()
const ListMap* lmap_p = MapMap_at(&mmap, "first");
const StackList* list_p = ListMap_at(lmap_p, 42);
const FloatStack* stack_p = StackList_back(list_p);
- printf("value is: %f\n", *FloatStack_at(stack_p, 3)); // pi
+ printf("value is: %f\n", (double)*FloatStack_at(stack_p, 3)); // pi
MapMap_drop(&mmap);
}
diff --git a/misc/examples/gauss2.c b/misc/examples/gauss2.c
index df709d03..e786824b 100644
--- a/misc/examples/gauss2.c
+++ b/misc/examples/gauss2.c
@@ -14,7 +14,7 @@ int main()
enum {N = 5000000};
uint64_t seed = (uint64_t)time(NULL);
crand_t rng = crand_init(seed);
- const double Mean = round(crand_f64(&rng)*98.f - 49.f), StdDev = crand_f64(&rng)*10.f + 1.f, Scale = 74.f;
+ const double Mean = round(crand_f64(&rng)*98.0 - 49.0), StdDev = crand_f64(&rng)*10.0 + 1.0, Scale = 74.0;
printf("Demo of gaussian / normal distribution of %d random samples\n", N);
printf("Mean %f, StdDev %f\n", Mean, StdDev);
diff --git a/misc/examples/inits.c b/misc/examples/inits.c
index 81bcdd3e..e098422e 100644
--- a/misc/examples/inits.c
+++ b/misc/examples/inits.c
@@ -45,7 +45,7 @@ int main(void)
puts("\npop and show high priorites first:");
while (! cpque_f_empty(&floats)) {
- printf("%.1f ", *cpque_f_top(&floats));
+ printf("%.1f ", (double)*cpque_f_top(&floats));
cpque_f_pop(&floats);
}
puts("\n");
diff --git a/misc/examples/make.sh b/misc/examples/make.sh
index 0297e5a1..ee8d2267 100755
--- a/misc/examples/make.sh
+++ b/misc/examples/make.sh
@@ -1,12 +1,12 @@
#!/bin/sh
if [ "$(uname)" = 'Linux' ]; then
- sanitize='-fsanitize=address'
+ sanitize='-fsanitize=address -fsanitize=undefined -fsanitize-trap'
clibs='-lm' # -pthread
oflag='-o '
fi
-cc=gcc; cflags="-s -O3 -std=c99 -Wconversion -Wpedantic -Wall -Wsign-compare -Wwrite-strings"
+cc=gcc; cflags="-s -O3 -std=c99 -Wall -Wextra -Wpedantic -Wconversion -Wwrite-strings -Wdouble-promotion -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-maybe-uninitialized -Wno-missing-field-initializers"
#cc=gcc; cflags="-g -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall $sanitize"
#cc=tcc; cflags="-Wall -std=c99"
#cc=clang; cflags="-s -O2 -std=c99 -Werror -Wfatal-errors -Wpedantic -Wall -Wno-unused-function -Wsign-compare -Wwrite-strings"
diff --git a/misc/examples/new_list.c b/misc/examples/new_list.c
index 8b291d34..14fabb4a 100644
--- a/misc/examples/new_list.c
+++ b/misc/examples/new_list.c
@@ -61,7 +61,7 @@ int main()
clist_float_sort(&flst);
c_foreach (i, clist_float, flst)
- printf(" %g", *i.ref);
+ printf(" %g", (double)*i.ref);
puts("");
clist_float_drop(&flst);
diff --git a/misc/examples/new_map.c b/misc/examples/new_map.c
index 3a4f934d..f01db64f 100644
--- a/misc/examples/new_map.c
+++ b/misc/examples/new_map.c
@@ -3,10 +3,10 @@
forward_cmap(cmap_pnt, struct Point, int);
-struct MyStruct {
+typedef struct MyStruct {
cmap_pnt pntmap;
cstr name;
-} typedef MyStruct;
+} MyStruct;
// int => int map
#define i_key int
@@ -14,7 +14,7 @@ struct MyStruct {
#include <stc/cmap.h>
// Point => int map
-struct Point { int x, y; } typedef Point;
+typedef struct Point { int x, y; } Point;
int point_cmp(const Point* a, const Point* b) {
int c = a->x - b->x;
diff --git a/misc/examples/new_pque.c b/misc/examples/new_pque.c
index 9147e3f2..5b26b3de 100644
--- a/misc/examples/new_pque.c
+++ b/misc/examples/new_pque.c
@@ -1,6 +1,6 @@
#include <stdio.h>
-struct Point { int x, y; } typedef Point;
+typedef struct Point { int x, y; } Point;
#define i_type PointQ
#define i_val Point
diff --git a/misc/examples/new_queue.c b/misc/examples/new_queue.c
index 916f4dbc..b784bc18 100644
--- a/misc/examples/new_queue.c
+++ b/misc/examples/new_queue.c
@@ -5,7 +5,7 @@
forward_cqueue(cqueue_pnt, struct Point);
-struct Point { int x, y; } typedef Point;
+typedef struct Point { int x, y; } Point;
int point_cmp(const Point* a, const Point* b) {
int c = c_default_cmp(&a->x, &b->x);
return c ? c : c_default_cmp(&a->y, &b->y);
diff --git a/misc/examples/new_smap.c b/misc/examples/new_smap.c
index d8245b8b..f930eba2 100644
--- a/misc/examples/new_smap.c
+++ b/misc/examples/new_smap.c
@@ -10,7 +10,7 @@ typedef struct {
} MyStruct;
// Point => int map
-struct Point { int x, y; } typedef Point;
+typedef struct Point { int x, y; } Point;
int point_cmp(const Point* a, const Point* b) {
int c = a->x - b->x;
return c ? c : a->y - b->y;
diff --git a/misc/examples/new_vec.c b/misc/examples/new_vec.c
index df443b7f..d4b66883 100644
--- a/misc/examples/new_vec.c
+++ b/misc/examples/new_vec.c
@@ -4,10 +4,10 @@
forward_cvec(cvec_i32, int);
forward_cvec(cvec_pnt, struct Point);
-struct MyStruct {
+typedef struct MyStruct {
cvec_i32 intvec;
cvec_pnt pntvec;
-} typedef MyStruct;
+} MyStruct;
#define i_val int
#define i_is_forward
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index d0887353..7efa26ff 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -26,15 +26,15 @@ cbits sieveOfEratosthenes(int64_t n)
int main(void)
{
- int64_t n = 1000000000;
- printf("Computing prime numbers up to %" c_ZI "\n", n);
+ int n = 1000000000;
+ printf("Computing prime numbers up to %d\n", n);
- clock_t t1 = clock();
+ clock_t t = clock();
cbits primes = sieveOfEratosthenes(n + 1);
- int64_t np = cbits_count(&primes);
- clock_t t2 = clock();
+ int np = (int)cbits_count(&primes);
+ t = t - clock();
- printf("Number of primes: %" c_ZI ", time: %f\n\n", np, (float)(t2 - t1) / (float)CLOCKS_PER_SEC);
+ printf("Number of primes: %d, time: %f\n\n", np, (double)t/CLOCKS_PER_SEC);
puts("Show all the primes in the range [2, 1000):");
printf("2");
c_forrange (i, 3, 1000, 2)
diff --git a/misc/examples/random.c b/misc/examples/random.c
index ea9c483e..e783fe55 100644
--- a/misc/examples/random.c
+++ b/misc/examples/random.c
@@ -4,7 +4,7 @@
int main()
{
- const size_t N = 1000000000;
+ const int N = 1000000000;
const uint64_t seed = (uint64_t)time(NULL), range = 1000000;
crand_t rng = crand_init(seed);
@@ -18,8 +18,8 @@ int main()
sum += (uint32_t)crand_u64(&rng);
}
diff = clock() - before;
- printf("full range\t\t: %f secs, %" c_ZI ", avg: %f\n",
- (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N);
+ printf("full range\t\t: %f secs, %d, avg: %f\n",
+ (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
crand_unif_t dist1 = crand_unif_init(0, range);
rng = crand_init(seed);
@@ -29,8 +29,8 @@ int main()
sum += crand_unif(&rng, &dist1); // unbiased
}
diff = clock() - before;
- printf("unbiased 0-%" PRIu64 "\t: %f secs, %" c_ZI ", avg: %f\n",
- range, (float)diff/CLOCKS_PER_SEC, N, (float)sum / (float)N);
+ printf("unbiased 0-%" PRIu64 "\t: %f secs, %d, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
sum = 0;
rng = crand_init(seed);
@@ -39,7 +39,7 @@ int main()
sum += (int64_t)(crand_u64(&rng) % (range + 1)); // biased
}
diff = clock() - before;
- printf("biased 0-%" PRIu64 " \t: %f secs, %" c_ZI ", avg: %f\n",
- range, (float)diff / CLOCKS_PER_SEC, N, (float)sum / (float)N);
+ printf("biased 0-%" PRIu64 " \t: %f secs, %d, avg: %f\n",
+ range, (double)diff/CLOCKS_PER_SEC, N, (double)sum/N);
}
diff --git a/misc/examples/regex_match.c b/misc/examples/regex_match.c
index def0ae7a..e49ebd0b 100644
--- a/misc/examples/regex_match.c
+++ b/misc/examples/regex_match.c
@@ -24,7 +24,7 @@ int main()
cstack_float_push(&vec, (float)atof(i.match[0].str));
c_foreach (i, cstack_float, vec)
- printf(" %g\n", *i.ref);
+ printf(" %g\n", (double)*i.ref);
// extracts the numbers only to a comma separated string.
cstr nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, CREG_R_STRIP);
diff --git a/misc/examples/shape.c b/misc/examples/shape.c
index d7116039..22e993db 100644
--- a/misc/examples/shape.c
+++ b/misc/examples/shape.c
@@ -62,9 +62,9 @@ static void Triangle_draw(const Shape* shape)
{
const Triangle* self = DYN_CAST(Triangle, shape);
printf("Triangle : (%g,%g), (%g,%g), (%g,%g)\n",
- self->p[0].x, self->p[0].y,
- self->p[1].x, self->p[1].y,
- self->p[2].x, self->p[2].y);
+ (double)self->p[0].x, (double)self->p[0].y,
+ (double)self->p[1].x, (double)self->p[1].y,
+ (double)self->p[2].x, (double)self->p[2].y);
}
struct ShapeAPI Triangle_api = {
@@ -109,7 +109,7 @@ static void Polygon_draw(const Shape* shape)
const Polygon* self = DYN_CAST(Polygon, shape);
printf("Polygon :");
c_foreach (i, PointVec, self->points)
- printf(" (%g,%g)", i.ref->x, i.ref->y);
+ printf(" (%g,%g)", (double)i.ref->x, (double)i.ref->y);
puts("");
}