summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-01-25 20:18:02 +0100
committerTyge Løvset <[email protected]>2023-01-25 20:18:02 +0100
commit68fd366ceaa919293d348ce15c2596d485160cec (patch)
treee50caaf6dc2952da36b5cd0c60252f94ee2b77ec /misc/examples
parentaf4c2d6d2f3353364632701ef8208a9dcbe18623 (diff)
downloadSTC-modified-68fd366ceaa919293d348ce15c2596d485160cec.tar.gz
STC-modified-68fd366ceaa919293d348ce15c2596d485160cec.zip
Updates on cspan ++.
Diffstat (limited to 'misc/examples')
-rw-r--r--misc/examples/forfilter.c8
-rw-r--r--misc/examples/gauss1.c2
-rw-r--r--misc/examples/multidim.c4
-rw-r--r--misc/examples/prime.c3
-rw-r--r--misc/examples/printspan.c2
-rw-r--r--misc/examples/shape.c12
6 files changed, 16 insertions, 15 deletions
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index e041fd68..fdc013a3 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -64,8 +64,8 @@ void demo2(void)
{
c_AUTO (IVec, vector) {
puts("demo2:");
-
- c_FORFILTER (x, crange, crange_literal(INT64_MAX)
+ crange R = crange_make(INT64_MAX);
+ c_FORFILTER (x, crange, R
, c_flt_skipwhile(x, *x.ref != 11)
&& *x.ref % 2 != 0
, c_flt_take(x, 5))
@@ -126,8 +126,8 @@ void demo5(void)
#define flt_even(i) ((*i.ref & 1) == 0)
#define flt_mid_decade(i) ((*i.ref % 10) != 0)
puts("demo5:");
- crange r1 = crange_make(1963, INT32_MAX);
- c_FORFILTER (i, crange, r1
+ crange R = crange_make(1963, INT32_MAX);
+ c_FORFILTER (i, crange, R
, c_flt_skip(i,15)
&& c_flt_skipwhile(i, flt_mid_decade(i))
&& c_flt_skip(i,30)
diff --git a/misc/examples/gauss1.c b/misc/examples/gauss1.c
index 519a7895..db103945 100644
--- a/misc/examples/gauss1.c
+++ b/misc/examples/gauss1.c
@@ -45,7 +45,7 @@ int main()
// Print the gaussian bar chart
c_FOREACH (i, cvec_ii, histvec) {
- int n = (int)(i.ref->second * StdDev * Scale * 2.5 / N);
+ int n = (int)(i.ref->second * StdDev * Scale * 2.5 / (double)N);
if (n > 0) {
printf("%4d ", i.ref->first);
c_FORRANGE (n) printf("*");
diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c
index 3eef1497..8a5492dc 100644
--- a/misc/examples/multidim.c
+++ b/misc/examples/multidim.c
@@ -15,9 +15,9 @@ int main()
// View data as contiguous memory representing 12 ints
ispan ms1 = cspan_from(&v);
// View data as contiguous memory representing 2 rows of 6 ints each
- ispan2 ms2 = cspan_make(v.data, 2, 6);
+ ispan2 ms2 = cspan_multidim(v.data, 2, 6);
// View the same data as a 3D array 2 x 3 x 2
- ispan3 ms3 = cspan_make(v.data, 2, 3, 2);
+ ispan3 ms3 = cspan_multidim(v.data, 2, 3, 2);
// write data using 2D view
for (unsigned i=0; i != ms2.dim[0]; i++)
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index 4a6b0f68..5c8d65d3 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -43,7 +43,8 @@ int main(void)
puts("");
puts("Show the last 50 primes using a temporary crange generator:");
- c_FORFILTER (i, crange, crange_literal(n - 1, 0, -2)
+ crange R = crange_make(n - 1, 0, -2);
+ c_FORFILTER (i, crange, R
, cbits_test(&primes, *i.ref>>1)
, c_flt_take(i, 50)) {
printf("%lld ", *i.ref);
diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c
index 227fd2ed..82b54367 100644
--- a/misc/examples/printspan.c
+++ b/misc/examples/printspan.c
@@ -27,7 +27,7 @@ int main()
c_AUTO (cdeq_int, deq)
c_AUTO (cset_str, set)
{
- intspan sp1 = cspan_init(intspan, {1, 2});
+ intspan sp1 = cspan_make(intspan, {1, 2});
printMe( sp1 );
printMe( c_make(intspan, {1, 2, 3}) );
diff --git a/misc/examples/shape.c b/misc/examples/shape.c
index ed0c3fe1..75a5e174 100644
--- a/misc/examples/shape.c
+++ b/misc/examples/shape.c
@@ -50,12 +50,12 @@ typedef struct {
Point p[3];
} Triangle;
-static struct ShapeAPI Triangle_api;
+extern struct ShapeAPI Triangle_api;
Triangle Triangle_from(Point a, Point b, Point c)
{
- Triangle t = {{.api=&Triangle_api}, .p={a, b, c}};
+ Triangle t = {.shape={.api=&Triangle_api}, .p={a, b, c}};
return t;
}
@@ -68,7 +68,7 @@ static void Triangle_draw(const Shape* shape)
self->p[2].x, self->p[2].y);
}
-static struct ShapeAPI Triangle_api = {
+struct ShapeAPI Triangle_api = {
.drop = Shape_drop,
.draw = Triangle_draw,
};
@@ -85,12 +85,12 @@ typedef struct {
PointVec points;
} Polygon;
-static struct ShapeAPI Polygon_api;
+extern struct ShapeAPI Polygon_api;
Polygon Polygon_init(void)
{
- Polygon p = {{.api=&Polygon_api}, .points=PointVec_init()};
+ Polygon p = {.shape={.api=&Polygon_api}, .points=PointVec_init()};
return p;
}
@@ -116,7 +116,7 @@ static void Polygon_draw(const Shape* shape)
puts("");
}
-static struct ShapeAPI Polygon_api = {
+struct ShapeAPI Polygon_api = {
.drop = Polygon_drop,
.draw = Polygon_draw,
};