ADT
        arm-eh
        ast-experimental
        enum
        forall-pointer-decay
        jacob/cs343-translation
        jenkins-sandbox
        new-ast
        new-ast-unique-expr
        pthread-emulation
        qualifiedEnum
      
      
        
          | Last change
 on this file since c93fd72 was             466fa01, checked in by Peter A. Buhr <pabuhr@…>, 6 years ago | 
        
          | 
add diagrams and example programs
 | 
        
          | 
              
Property                 mode
 set to                 100644 | 
        
          | File size:
            672 bytes | 
      
      
| Line |  | 
|---|
| 1 | #include <stdio.h> | 
|---|
| 2 |  | 
|---|
| 3 | void mary() { | 
|---|
| 4 | printf( "MARY\n" ); | 
|---|
| 5 | } | 
|---|
| 6 |  | 
|---|
| 7 | #define FIB_INIT { 0 } | 
|---|
| 8 | typedef struct { int next; int fn1, fn2; } Fib; | 
|---|
| 9 | int fib( Fib * f ) { | 
|---|
| 10 | static void * states[] = { &&s1, &&s2, &&s3 }; | 
|---|
| 11 | goto *states[f->next]; | 
|---|
| 12 | s1: | 
|---|
| 13 | mary(); | 
|---|
| 14 | f->fn1 = 0; | 
|---|
| 15 | f->next = 1; | 
|---|
| 16 | return f->fn1; | 
|---|
| 17 | s2: | 
|---|
| 18 | mary(); | 
|---|
| 19 | f->fn2 = f->fn1; | 
|---|
| 20 | f->fn1 = 1; | 
|---|
| 21 | f->next = 2; | 
|---|
| 22 | return f->fn1; | 
|---|
| 23 | s3:; | 
|---|
| 24 | mary(); | 
|---|
| 25 | int fn = f->fn1 + f->fn2; | 
|---|
| 26 | f->fn2 = f->fn1; | 
|---|
| 27 | f->fn1 = fn; | 
|---|
| 28 | return fn; | 
|---|
| 29 | } | 
|---|
| 30 | int main() { | 
|---|
| 31 | Fib f1 = FIB_INIT, f2 = FIB_INIT; | 
|---|
| 32 | for ( int i = 0; i < 10; i += 1 ) { | 
|---|
| 33 | printf( "%d %d\n", fib( &f1 ), fib( &f2 ) ); | 
|---|
| 34 | } | 
|---|
| 35 | } | 
|---|
| 36 |  | 
|---|
| 37 | // Local Variables: // | 
|---|
| 38 | // tab-width: 4 // | 
|---|
| 39 | // compile-command: "gcc Fib2.c" // | 
|---|
| 40 | // End: // | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.