source:
doc/papers/concurrency/examples/Fib.c
@
16e6905
Last change on this file since 16e6905 was 600d7be, checked in by , 5 years ago | |
---|---|
|
|
File size: 400 bytes |
Rev | Line | |
---|---|---|
[17c6c1c3] | 1 | #include <stdio.h> |
2 | ||
[600d7be] | 3 | typedef struct { |
4 | int fn1, fn; | |
5 | } Fib; | |
[17c6c1c3] | 6 | |
[600d7be] | 7 | #define FibCtor { 1, 0 } |
[17c6c1c3] | 8 | |
[600d7be] | 9 | int fib( Fib * f ) { |
10 | int fn = f->fn; f->fn = f->fn1; | |
11 | f->fn1 = f->fn + fn; | |
12 | return fn; | |
[17c6c1c3] | 13 | } |
14 | int main() { | |
[600d7be] | 15 | Fib f1 = FibCtor, f2 = FibCtor; |
[17c6c1c3] | 16 | for ( int i = 0; i < 10; i += 1 ) { |
17 | printf( "%d %d\n", fib( &f1 ), fib( &f2 ) ); | |
18 | } | |
19 | } | |
20 | ||
21 | // Local Variables: // | |
22 | // tab-width: 4 // | |
23 | // compile-command: "gcc Fib.c" // | |
24 | // End: // |
Note: See TracBrowser
for help on using the repository browser.