Changes between Version 5 and Version 6 of C Interface


Ignore:
Timestamp:
02/15/10 13:41:24 (16 years ago)
Author:
Stephen Siegel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • C Interface

    v5 v6  
    3333== Abstract Functions ==
    3434
     35== Example ==
     36Here is a program that adds the elements in a file.  The commandline argument is the filename.   Inputs are the filename, the contents of the file, and the parameter B which is an upper bound on the number of elements that will be read.  Output is to stdout.
     37
     38How do we annotate this file in such a way that it does not interfere with compilation, but provides all the information we need to build a TASS model?
     39
     40
     41{{{
     42#include<stdio.h>
     43#include<assert.h>
     44/*@ _TASS_input {B>0} */
     45#define B 3
     46
     47double sum = 0.0;
     48
     49/* arguments to main are inputs */
     50int main(int argc, char* argv[]) {
     51  char *filename;
     52  double result = 0.0;
     53  FILE *fp;
     54  double tmp;
     55  int i = 0;
     56
     57  if (argc != 2) {
     58    printf("Usage: realadder filename\
     59");
     60    fflush(stdout);
     61    return 1;
     62  }
     63  filename = argv[1];
     64  fp = fopen(filename, "r");
     65  assert(fp);
     66  while (1) {
     67    /*@ _TASS_corresponds spec@label */
     68    int more = fscanf(fp, "%lf", &tmp);
     69
     70    /*@ _TASS_assume(tmp>=0.0) */
     71    if (more == EOF) break;
     72    i++;
     73    if (i>B) {
     74      printf("Too many numbers!  Limit is %d.\
     75", B);
     76      fflush(stdout);
     77      return 2;
     78    }
     79    sum += tmp;
     80  }
     81  printf("The sum is %lf\
     82", sum);
     83  fclose(fp);
     84  return 0;
     85}
     86}}}
     87
     88Idea: the result of fscanf can be represented as a symbolic function.  In other words, add functions:
     89{{{
     90_TASS_read_int(string filename, int position)
     91_TASS_read_real(string filename, int position)
     92}}}
     93Or something like that.
     94
     95
     96
     97Questions:
     98* do we need to add char (and string?) datatypes to TASS?
     99