Last change
on this file since 6804f38 was
466fa01,
checked in by Peter A. Buhr <pabuhr@…>, 5 years ago
|
add diagrams and example programs
|
-
Property mode set to
100644
|
File size:
476 bytes
|
Line | |
---|
1 | #include <cstdio> |
---|
2 | |
---|
3 | struct Fib { |
---|
4 | int fn = 1, fn1 = 0; |
---|
5 | void * next = nullptr; |
---|
6 | |
---|
7 | int operator()() { |
---|
8 | if ( __builtin_expect(next != 0, 1) ) goto *next; |
---|
9 | next = &&s1; |
---|
10 | for ( ;; ) { |
---|
11 | return fn1; |
---|
12 | s1: ; |
---|
13 | int fn0 = fn + fn1; |
---|
14 | fn1 = fn; |
---|
15 | fn = fn0; |
---|
16 | return fn1; |
---|
17 | } |
---|
18 | } |
---|
19 | }; |
---|
20 | int main() { |
---|
21 | Fib f1, f2; |
---|
22 | for ( int i = 0; i < 10; i += 1 ) { |
---|
23 | printf( "%d %d\n", f1(), f2() ); |
---|
24 | } |
---|
25 | } |
---|
26 | |
---|
27 | // Local Variables: // |
---|
28 | // tab-width: 4 // |
---|
29 | // compile-command: "gcc-8 Fib3.cc" // |
---|
30 | // End: // |
---|
Note: See
TracBrowser
for help on using the repository browser.