Ignore:
Timestamp:
Jun 4, 2019, 6:28:55 PM (5 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
7261e3c
Parents:
466fa01
Message:

example updates

File:
1 edited

Legend:

Unmodified
Added
Removed
  • doc/papers/concurrency/examples/Fib.c

    r466fa01 r600d7be  
    11#include <stdio.h>
    22
    3 #define FIB_INIT { 0, 1 }
    4 typedef struct { int fn1, fn; } Fib;
     3typedef struct {
     4        int fn1, fn;
     5} Fib;
     6
     7#define FibCtor { 1, 0 }
     8
    59int fib( Fib * f ) {
    6 
    7         int ret = f->fn1;
    8         f->fn1 = f->fn;
    9         f->fn = ret + f->fn;
    10 
    11         return ret;
     10        int fn = f->fn; f->fn = f->fn1;
     11                f->fn1 = f->fn + fn;
     12        return fn;
    1213}
    1314int main() {
    14         Fib f1 = FIB_INIT, f2 = FIB_INIT;
     15        Fib f1 = FibCtor, f2 = FibCtor;
    1516        for ( int i = 0; i < 10; i += 1 ) {
    1617                printf( "%d %d\n", fib( &f1 ), fib( &f2 ) );
Note: See TracChangeset for help on using the changeset viewer.