source: doc/papers/llheap/examples/Fib3.c @ 1ae3ac46

Last change on this file since 1ae3ac46 was 7bef8cf, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

start paper on llheap

  • Property mode set to 100644
File size: 541 bytes
Line 
1#include <stdio.h>
2
3typedef struct {
4        int restart, fn1, fn;
5} Fib;
6#define FibCtor { 0, 1, 0 }
7
8Fib * comain( Fib * f ) {
9        static void * states[] = {&&s0, &&s1};
10        goto *states[f->restart];
11  s0: f->restart = 1;
12        for ( ;; ) {
13                return f;
14          s1:; int fn = f->fn + f->fn1;
15                f->fn1 = f->fn; f->fn = fn;
16        }
17}
18int main() {
19        Fib f1 = FibCtor, f2 = FibCtor;
20        for ( int i = 0; i < 10; i += 1 )
21                printf( "%d %d\n", comain( &f1 )->fn, comain( &f2 )->fn );
22}
23
24// Local Variables: //
25// tab-width: 4 //
26// compile-command: "gcc-8 Fib3.c" //
27// End: //
Note: See TracBrowser for help on using the repository browser.