summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/triples.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-02-28 08:40:40 +0100
committerTyge Løvset <[email protected]>2023-02-28 08:40:40 +0100
commit0fb86f00db4f1d3600ec1b91d0a4e2ef8f778164 (patch)
treeb2b65809bda272f73fa06147df549e6f889886b5 /misc/examples/triples.c
parentd2228c3dc993e47c8d2df951230cf43a93299f5f (diff)
downloadSTC-modified-0fb86f00db4f1d3600ec1b91d0a4e2ef8f778164.tar.gz
STC-modified-0fb86f00db4f1d3600ec1b91d0a4e2ef8f778164.zip
Fixed coroutine.h and examples. cco_return; has no arguments.
Diffstat (limited to 'misc/examples/triples.c')
-rw-r--r--misc/examples/triples.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/misc/examples/triples.c b/misc/examples/triples.c
index e85558a3..05e6fca2 100644
--- a/misc/examples/triples.c
+++ b/misc/examples/triples.c
@@ -18,22 +18,27 @@ void triples_vanilla(int n) {
}
struct tricoro {
+ int n;
int cco_state;
int x, y, z;
};
+#include <stdlib.h>
+
bool triples_coro(struct tricoro* t) {
cco_begin(t);
for (t->z = 1;; ++t->z) {
for (t->x = 1; t->x < t->z; ++t->x) {
for (t->y = t->x; t->y < t->z; ++t->y) {
if (t->x*t->x + t->y*t->y == t->z*t->z) {
+ if (t->n-- == 0) cco_return;
cco_yield(true);
}
}
}
}
cco_final:
+ puts("final");
cco_end(false);
}
@@ -41,12 +46,10 @@ bool triples_coro(struct tricoro* t) {
int main()
{
puts("Vanilla triples:");
- triples_vanilla(20);
+ triples_vanilla(6);
puts("\nCoroutine triples:");
- struct tricoro t = {0};
- int i = 0;
- while (i++ < 20 && triples_coro(&t))
+ struct tricoro t = {6};
+ while (triples_coro(&t))
printf("{%d, %d, %d},\n", t.x, t.y, t.z);
- triples_coro(cco_stop(&t));
} \ No newline at end of file