Journal Articles

CVu Journal Vol 14, #1 - Feb 2002
Browse in : All > Journals > CVu > 141 (8)

Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.

Title: Members' Experiences

Author: Administrator

Date: 03 February 2002 13:15:49 +00:00 or Sun, 03 February 2002 13:15:49 +00:00

Summary: 

Body: 

Dear Editor,

I have the following comments related to Members' Experiences reported by Francis in the last issue of C Vu.

  1. We have recently released Ch version 2.1. Ch Standard Edition is now free for unlimited use by students, instructors, and employees of non-profit organizations.

    Ch is a C interpreter with C++ classes. Ch 2.1 supports C90 and many new features such as complex numbers, variable length arrays (VLA), IEEE floating-point arithmetic, generic functions in C99, as well as industry standards POSIX, X11/Motif, OpenGL, ODBC, GTK+. Ch 2.1 for Windows has extensive collections of Unix utilities including vi, ls, awk, sed, grep, cp, find, etc. It is quite effective for cross platform shell programming in C.

  2. For passing arrays of different starting index and length to a function, the upper bound of the array can be omitted. That is, the function prototype void printout(int primes[0:upper]); can be changed to void printout(int primes[0:]); so that arrays with different upper and lower bounds can be passed to the function. The number of elements of the array passed can be obtained by the generic function shape() which returns a computational array with the shape of the passed array. Using this scheme, Francis' prime number generating program can be re-written as follows:

    #include <iostream.h>
    #define upper 1000000
    void printout(int primes[0:]){
      int newline = 0;
      int i;
      int num;
      num = (int)shape(primes);
      for(i=0; i<num; i++){
        if(primes[i]){
          newline++;
          if(newline>10){
            cout << "\n";
            newline=0;
          }
          cout << primes[i] <<' ';
        }
      }
      cout << primes[num]; 
    // warning for array out of bounds
      cout << primes[num+1];    
    // warning for array out of bounds
    }
    int main(){
      int primes[1:upper];
      int i=0;
      for(i=1; i<=upper; i++){
        primes[i] = i*2-1;
      }
      primes[1] = 0;
      int mark=3;
      do{
        for(i=mark*mark/2+1; i<=upper; i+=mark){
          primes[i]=0;
        }
        for(i=(mark+1)/2 + 1; i<=upper; i++){
          if(primes[i]){
            mark=primes[i];
            break;
          }
        }
      }while(mark*mark<upper);
      printout(primes);
      return 0;
    }
    

    Using the above defined function printout(), arrays with different length and bounds can be passed to it as shown below without a warning message at the parsing stage.

    #define upper 1000000
    int main() {
      int primes1[1:upper];
      int primes2[0:upper+1];
    /* ... */
      printout(primes1);
      printout(primes2);
    /* ... */
    }
    
  3. The foreach-loop in Ch can be iterated in following three forms:

    foreach(token; expr1; expr2; expr3) 
      statement
    foreach(token; expr1; expr2) 
      statement
    foreach(token; expr1) 
      statement
    

    Arguments token, expr1, expr2 and expr3 can be of either string type or pointer to char. For example, the following code

      char *s;
      foreach(s;"123 456 789"){
        printf("s = %s\n", s); 
      }
      char *cond=NULL;
      char *delimit = ": ";
      foreach(s;"abc:def ABC"; cond; delimit){
        printf("s = %s\n", s); 
      }
      /* output:
         s = 123
         s = 456 
         s = 789
         s = adb
         s = def
         s = ABC
      */
    

    is valid in Ch.

Notes: 

More fields may be available via dynamicdata ..