Frequently Asked Questions
  1. What is Ch?
  2. Why using the name Ch?
  3. Is Ch a new language?
  4. What are the differences between Ch and other languages and software packages?
  5. What is the relation between Ch and C/C++?
  6. What are Ch extensions to C?
  7. What are the differences between Ch and Java™?
  8. What are the differences between Ch and conventional Unix shells?
  9. What are the differences between Ch and C++?
  10. What are the differences between Ch and Fortran?
  11. What are the differences between Ch and Basic?
  12. What are the differences between Ch and mathematical packages?
  13. How do you compare Ch with Perl and CGI?
  14. Can Ch be used for World-Wide Distributed Computing?
  15. On what platforms does Ch run?
  16. Can Ch code be compiled into binary?
  17. How can Ch code in ChIDE be exported in a Word file with syntax highlinghting?

Q:What is Ch?

Ch is an embeddable C/C++ interpreter for cross-platform scripting, shell programming, 2D/3D plotting, quick animation, numerical computing, and embedded scripting. C/Ch/C++ allow users to use one language, anywhere and everywhere, for any programming tasks. It is a scripting language like Perl, Python or Bash.

Q:Why using the name Ch?

Ch means C with high-level extensions. Also, Ch contains the initials of last and first name of Harry Cheng, the Ch chief architect.

Q:Is Ch a new language?

No, Ch is not a new language. Ch is C+. Similar to gcc, VC++® and Sun cc which are C compilers that conform to the C language standard ratified by ANSI and ISO, Ch is interpretive implementation of the C language. It supports C99, C++ class, POSIX, C LAPACK, CGI, OpenGL, ODBC, X/Motif, Win32 and GTK+.

Like all C compilers, our C interpreter also has some extensions to the C standard. Some extensions in Ch such as complex numbers and variable length arrays (VLAs) have been adopted in the latest ISO C standard called C99. Ch supports more new features in C99 than most existing C compilers. C99 features supported in Ch are listed here.

Q: What is the relation between Ch and other major computer programming languages and software packages?

The relation between Ch and other major computer programming languages and software packages can be illustrated in a diagram below.

Q: What is the relation between Ch and C/C++

C++ is C plus plus minus. Ch is C plus (Ch = C+). Ch is a C interpreter. Ch is C with classes and high-level extensions. Ch is a superset of C. Note that C++ is no longer a superset of C. For example, VLA and IEEE floating-point arithmetic in C are not supported in C++.

C is for low-level system programming and embedded systems; C++ for large-scale projects. Ch is optimal for platform-independent scripting in numerical computing and visualization, rapid application development, Web programming and plotting, embedded scripting, shell programming, integration with legacy systems, and learning C/C++.

Q:What are Ch extensions to C?

Like C++, Ch is designed to be a superset of C, which means a C program can run in Ch without modification. Unlike C++ which is designed for serious professional programmers (elite), Ch is designed for both novice beginners with no computer experience (average Joe and John) as well as experienced programmers. Many weakness in C is addressed in Ch. Major extensions to C in Ch are as follows.

  • Cross platform shell programming
    Ch is C comptabile unix shell and it works in Windows/Linux/MacOSX/Unix. The shell features such as Foreach-loop, Here document, Verbatim output and variable substitution are supported. It can be used as a login shell in Unix/Linux/MacOSX.

  • C++ Classes, objects, and encapsulation for object-based programming.

  • Built-in array boundary check at run time
    the array boundary is checked when an element of array is accessed at run time. The string length is checked when an array of chars is updated as a string. The error will be issued when the array size exceeds its limit for safety operation.

  • Embedded Scripting
    Ch can be embedded into C/C++ applications for embeddable scripting. The pointer can be used between C/C++ binary functions and Ch, no additioal wrapping code is needed. It is easy to call back the binary C functions from Ch script or call the Ch function from binary C space. The debug is also supported via embedded Ch API.

  • Variables are initialized upon declaration
    Variables, pointers declaration and memories allocated by memory allocation functions are automatically initialized with 0 or NULL.

  • Support reflection It is easy to evaluate a string at run time with streval().

  • Support function overloading and polymorphism with variable arguments in a function
    Standard C requires at least one fixed argument. Ch extends C with more flexibility. It supports variable length argument without specifying the first named argument in the form of "type funcname(...)". Thus the number and types of arguments are flexible. It can be used for overloading and polymorphism.

  • Computational array for numerical computing
    An array qualified by type qualifier array is called computational array. A computational array is treated as a first-class object as in Fortran 90. For example,
           #include <array.h>
           array float a[10][10], b[10][10];
           a += b+inverse(a)*transpose(a)+sin(a);
    

  • Mathematical function extensions
    Follow conventional mathematics in complex analysis, there is only one complex infinity and one complex-not-a-number. Complex numbers are defined in the entire complex domain with complex metanumbers ComplexInf and ComplexNaN. Different branches of multiple-valued complex functions can be obtained by mathematical functions with optional arguments. For example, the square root of -1 has two values of unit imaginary numbers i and -i. They can be obtained by generic function sqrt() in Ch as follows.
    > sqrt(-1.0)
    NaN
    > sqrt(complex(-1.0,0))
    complex(0.0000,1.0000)
    > sqrt(complex(-1.0,0), 0)
    complex(0.0000,1.0000)
    > sqrt(complex(-1.0,0), 1)
    complex(-0.0000,-1.0000)
    > sqrt(-1, 0)
    complex(0.0000,1.0000)
    > sqrt(-1, 1)
    complex(-0.0000,-1.0000)
    >
    
  • Support string data type String is a first-class object in Ch, it can allocate and deallocate the memory automatically. For example,
          string_t s, a[3];
          s = "great string";
          strcpy(a[0], s);
          strcat(s, s);
          printf("s = %s\n", s);
    
  • Functions can be nested and recursively nested similar to its implementation in GNU gcc.
    For example,
          int func1() {
             void func2() {
                int func3() { ...}
             }
             ...
             func2();
          }  
    
  • Extentions for deferred-shape arrays, assumed-shape arrays, and pointer to assumed-shape arrays
    Multi-dimensional arrays in C are difficult to handle with double pointers. They are valid in Ch. But, arrays of variable length (VLA) including deferred-shape arrays, assumed-shape arrays, and pointer to assumed-shape arrays in Ch provide more elegant interface. The following example demonstrates the simplicity of VLA.
      void funct(int a[:][:], (*b)[:], n, m){
      /* a: assumed-shape array */
      /* b: pointer to its array of assumed-shape */
        int e[n][m];     /* e: deferred-shape array */
        int (*f)[:];     /* f: pointer to array of assumed-shape */
        f = a;
        e[1][2] = a[2][3];
      }
      int A[3][4], B[5][6];
      funct(A, B, 10, 20);
      funct(B, A,  85, 85);
    
  • Arrays of adjustable range. The range of subscript for an index of array can be adjusted. For example,
      int a[1:10], b[-5:5], c[0:10][1:10], d[10][1:10], e[n:m], f[n1:m1][1:m2];
      extern int a[1:], b[-5:], c[0:][1:10];
      int funct(int a[1:], int b[1:10], int c[1:][3], int d[1:10][0:20]);
      a[10] = a[1]+2; /* OK */
      a[0] = 90;      /* Error: index out of range */
    

      void funct2(int a[0:]) {
          int i;
          int num=(int)shape(a); // num is 10, 10, 11 for a1, a2, a3, respectively
          for(i=0; i<num; i++) {
             a[i] *= 2;  /* multiply each element of the array by 2 */
          }
      }
      int main() {
         int a1[10];    // a[0], ... a[8], a[9]
         int a2[1:10];  // a[1], ... a[9], a[10]
         int a3[0:10];  // a[0], ... a[8], a[9], a[10]
         /* ... */
         funct2(a1);
         funct2(a2);
         funct2(a3);
      }
    
    
  • Reference type
    Functions can be called by reference. The same syntax in C++ is used in Ch. For example,
      void swap(int& i, int& j){
        int tmp = i;
        i = j;
        j = tmp;
      }
      int main() {
        int i;
        int &j = i;
        int A, B;
        swap(A, B);    /* pass by reference as in Fortran */
      }
    
  • cross platform built-in 2D/3D graphical plottings
    High-level function files such as plotxy(), plotxyz(), plotxyf(), plotxyzf() for plotting. For example, the following Ch program can plot a sine wave on your screen without compilation.
        #include <math.h>
        #include <chplot.h>
        int main() {
            int numpoints = 36;
            array double x[numpoints], y[numpoints];
    
            linspace(x, 0, 360);
            y = sin(x*M_PI/180);
            plotxy(x, y, "Ch plot", "xlabel", "ylabel");
        }
    
  • The index of a switch statement can be string in addition to integral constants.
    For example,
    string_t hostname=`hostname`;
    switch (hostname) {
        case "workmachine":
            fetchmail;
            break;
        case "homemachine":
            echo Ch is cool! I can now use a C program to backup files
            dump 0ubdsf 80 50000 50000 /dev/nrst0 /dev/sd0a
            break;
        default:
            break;
    }
    
  • A member of class/struct/union can be a pointer to assumed-shape arrays.
    That means a member of class/struct/union can be an array of variable length. This powerful feature can be illustrated by the following interactive commands executed in a Ch shell.
    > struct tag {             \
    >    int (*a)[:];          \ 
    >    array int (*b)[:];    \
    > }s 
    > int a1[2][3], a2[3][4]
    > array int b1[2][3]= {1,2,3,4,5,6}
    > array int b2[3][4]= {1,2,3,4,5,6,7,8,9,10,11,12}
    > s.a = a1; /* s.a and a1 share the memory */s
    > a1[1][2] = 10;
    > s.a[1][2] 
    10
    > s.a = a2; /* s.a and a2 share the memory */
    > s.a[1][2] = 20
    > a2[1][2] 
    20
    > a1[1][2] 
    10
    > s.b = (array int [:][:])b1
    > s.b 
    1 2 3 
    4 5 6 
    > s.b[1][1] = 100
    > b1
    1 2 3 
    4 100 6 
    > s.b = (array int [:][:])b2
    1 2 3 4 
    5 6 7 8 
    9 10 11 12 
    >
    
  • Array of reference is supported
    Arrays of different shape and data type can be passed to arguments of functions with array of reference type.

  • Support hexadecimal format '%x' in printf(), sprintf() etc functions

    decimal octal hexadecimal binary
    printf("%d", 15); printf("%o", 15); printf("%x", 15); printf("%b", 15);

Q: What are the differences between Ch and Java™?

Comparing Ch with Java™ is like comparing an orange with an apple. These two language environments are quite different in many ways. However, the following notes highlight the similarities and differences between Ch applets and Java™ applets for network computing.

Similarities between Ch and Java™

  • Both are interpretive.
  • Both treat string data type as a first-class object.
  • Both can pass information by reference.
  • The sizes of non-aggregate data types are fixed .

Differences between Ch and Java™

  • Ch is designed to be a superset of C with classes from C++. Ch programs can also be written in Fortran and Basic styles. The Ch language environment is similar to C shell. So Ch programmers can drawn upon their experience of using C, Fortran, Basic, C-shell and other software packages. As a result, Ch is simple, old-fashioned, and can be readily used to integrate legacy systems with the latest Web technologies. On the other hand, Java™ is almost a subset of C++. It is buzzword-compliant, object-oriented, blah-blah, ...
  • There is no pointer in Java™. Although C pointer poses a potential problem, it is the pointer that makes C so flexible and powerful. To be a superset of C, pointers are retained in Ch. But, for secure across network computing, functionalities related to pointer are restricted in Ch applets However, a Ch applet can invoke functions with pointers supplied by the client.
  • Arrays are not treated as pointers in Java™. To be a superset of C, array variable can be treated as a pointer in Ch. But, it is also a true array. The boundary of each array index is checked at runtime. In addition, the array can be handled as a first-class object like a matrix. The start and end index can be explicitly specified by the programmer.
  • Ch is a truly interpretive language environment. In Ch, what you see is what you get. There is no intermediate code in Ch. A Ch applet is executed without compilation. Java is a hybrid interpretive language environment. In Java, a program written in Java class has to be compiled as a so-called byte machine code before it can be integrated with html files as an applet. There is a potential security loophole for forging a pointer and sneaking the code to the bytecode, although extensive bytecode verification may detect forged pointers. Therefore, the security of Ch applets is one layer tighter than that of Java applets. Because Java programs are compiled, you still have all the problems related to compilation. How do you know an applet in bytecode you are invoking is the same one compiled from the latest version of the corresponding Java program? Therefore, like compiled languages, Java is more difficult to use for a team project.
  • Ch is a procedural/object-oriented language environment with the same programming paradigm of C, C++, Fortran, Basic and C shell. Like C shell, programming in Ch is a very high-level fourth generation shell programming. Java is object-oriented. If you deal with a large project with complicated data structure and you are object-oriented, you may like Java. On the other hand, if your program is small, purely object-oriented programming is overkill.
  • Ch is a shell for novice users, Java is not.
  • Ch supports computational arrays, and arrays of variable length, arrays of adjustable range. Java does not.
  • Ch can pass arguments to a function by value or by reference. There is no such a function in Java. Information is passed to a class by reference.
  • If you use the common set of Ch and C code, you can compile your Ch programs in any machine ranging from desktop to supercomputer for fast execution. Your existing legacy C code can be used without modification (Actually, sometimes, your C code needs to be slightly modified. Just like the differences between C++ and C, there are slight differences between Ch and C). Ch is designed also for real-time applications. It is clean; there is no garbage in Ch. Java collects garbage through multi-threading.
  • Java supports multi-threading, Ch does not. Ch supports multi-threading through native C binary interface.

Q: What are the differences between Ch and conventional Unix shells?

Ch is a C compatible shell, csh (C shell) is a C like shell.
The language syntax of conventional Unix shells such as Bourne shell, Korn shell, BASH shell, and C shell are awkward. Although these shells are often claimed as very high-level languages (VHLL), their symbolic mnemonic forms are similar to lower level assembly languages. The special meanings for clusters of metacharacters in these Unix shells are difficult to remember. Therefore, shell scripts written in these Unix shell programming languages are hard to read and difficult to change. Like millions of hard-to-program VCRs blinking 12:00 in American living rooms, only a fraction of the capabilities of these shell programming languages are used by the majority of Unix users. Most users including seasoned programmers treat these Unix shells as command interpreters only; their day-to-day programming tasks are handled in C or other conventional programming languages. Only the very unfortunate will have to read and write scripts in these conventional Unix shells. Ch bridges the gap between the C language and Unix shell. It is designed for both interactive command interpretation and shell programming. Ch is a true VHLL for programming while it retains the familiar interpretive features. Ch is the light in a tunnel for those unfortunate as well as lucky ones.

More information about shell programming in Ch is available here.

Q: What are the differences between Ch and C++?

Ch will be as close to C++ as possible, but no closer. Many complicated features in C++ are intentionally left out to retain the simplicity of Ch. The following C++ features are available in Ch:

  • Member function.
  • Mixed code and declaration.
  • The this-> pointer.
  • Reference type and pass-by-reference.
  • Function-style type conversion.
  • Class.
  • private/public data and functions in class. Ch is compatible with C++ that by default, members of a class definition are assumed to be private until a `public' declaration is given.
  • Static member of class/struct/union.
  • member functions. (they need to be defined outside a class/struct for a simple and consistent coding style)
  • The new and delete operators.
  • The constructor and destructor.
  • Polymorphic functions.
  • The scope resolution operator :: .
  • The I/O cout, cerr, cin with endl.
  • Arguments for variadic functions are optional.
Ch supports classes in C++ with the following additional capabilities:
  • Classes inside member functions.
  • Nested functions with classes.
  • Pass member function to argument of pointer-to-function type of functions.
C++ feature std::string is not supported. However, Ch uses string_t instead.

Q: What are the differences between Ch and Fortran?

Fortran is a simple language for engineers and scientists. Ch merges C and Fortran. Ch will be as close to Fortran as possible, but no closer.

The following Fortran features are available in Ch:

  • Complex is built-in data type.
  • Commonly used functions are built into the language. And they are polymorphic.
  • Arguments can be passed to functions by reference.
  • Variable length arrays including deferred-shape arrays, assumed-shape arrays, and pointer to assumed-shape arrays are easy to use.
  • The range of the array index can be adjusted to start with 1 or any number.
  • Computational arrays are treated as first-class objects.

Q: What are the differences between Ch and Basic?

Ch retains the simplicity of Basic. But, Ch is more powerful than Basic for many applications. Basic programs are typically written to run in Microsoft Windows platform only. Ch programs can run across different platforms.

Q: What are the differences between Ch and mathematical packages?

Special mathematical software packages such as MATLAB®, Mathematica®, and Maple® are appealing to engineers because of its graphical features and capabilities of manipulation of matrices. These high-level graphical and numerical features are available in Ch as shown in feature comparison and function comparison of Ch with MATLAB and Mathematica. Almost all these packages provide a mechanism to interface with C, such as translating the source code written in their language to the C language. But why bother that? Ch is a superset of ISO C widely supported by computer industry. Your C code can be readily used in Ch, and Ch code can be readily compiled in a C compiler, if you use common set of C and Ch.

Q: How do you compare Ch with Perl and CGI?

Perl is widely used in CGI programming. Since Ch is a superset of C interpreter with classes in C++, CGI programming in Ch is simple. It is as easy to use as JSP and ASP.

Q: Can Ch be used for network computing?

Many secure features have been designed and built into safe Ch. Safe Ch applets can be created dynamically on the fly for network computing.

Q: On what platforms does Ch run?

Ch runs on Windows 32, Windows 64, Linux 32 and Linux 64, LinuxPPC, Mac OS X, FreeBSD, Solaris Sparc, Solaris X86 32 bit, HP-UX, QNX and AIX 64 bit.

Q: Can Ch code be compiled into binary?

If the subset (C90 or C99 or C++) of Ch is used, an executable can be generated using any C/C++ compiler. We don't provide the compiler. You may check the compiler venders for your favorite operating system.

If you want to compile the Ch graphical functions, you need to use SoftIntegration C++ Graphical Library.

Q: How can Ch code in ChIDE be exported in a Word file with syntax highlinghting?

Export the code in .RTF or PDF file first using the commands "File", "Export", "As RTF" or "As PDF".