Next: , Previous: , Up: Usage   [Contents][Index]


5.2 Examples

The examples in this section illustrate various applications of the software evolution library.

We start with a C program for computing the greatest common demominator (gcd) of two numbers. The source file is available in test/etc/gcd/gcd.c, and reproduced below.

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]) {
  double a;
  double b;
  double c;
  double r1;
  double r2;

  a = atoi(argv[1]);
  b = atoi(argv[2]);

  if (a == 0) { printf("%g\n", b); }
  else        { }
  {
    while (b != 0) {
      if (a > b) {
        a = a - b;
      } else {
        b = b - a;
      }
    }
    printf("%g\n", a);
  }

  return 0;
}

(You may notice at this point that the C code is buggy and does not compute correct gcd for all inputs. The Repair example will demonstrate how SEL can be used to create a repaired version of the program.)

The examples operate on the ASM file compiled from gcd.c. If you would like to try out the examples yourself, compile gcd.c to ASM. For example:

$(CC) gcd.c -S -o gcd.s