source: doc/papers/concurrency/examples/Fib3.c @ d7a02ae

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since d7a02ae was 466fa01, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

add diagrams and example programs

  • Property mode set to 100644
File size: 534 bytes
Line 
1#include <stdio.h>
2
3typedef struct {
4        int fn1, fn;
5        void * next;
6} Fib;
7#define FibCtor { 1, 0, NULL }
8
9Fib * comain( Fib * f ) {
10        if ( __builtin_expect(f->next != 0, 1) ) goto *f->next;
11        f->next = &&s1;
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.