Getting Started


Table of Contents
Introduction

Like mastering a natural language, it takes time to perfect one's skill in any programming language. Contending multiple languages is a difficult task. Ch helps programmers to learn C language once and use it anywhere for almost any programming purpose.

Ch is a very high-level language environment (VHLL). It can help you to better understand computer programming and its applications. Ch makes hard things easy and easy things easier. If you do any of the following tasks, you may find that Ch language environment will make your life a little easier.

  • Write programs in C/C++.
  • Programming with scientific numerical computation.
  • Use computers in different platforms such as Windows, Unix, and Linux.
  • Develop interactive Web contents.
  • Rapid application development and deployment.
  • Unix/Windows system and Web server administration.
  • Research and teaching in engineering and science.
  • Learning how to write computer programs.
So what is Ch? Ch is C+. Ch is superset of C with salient features from C++ and other languages. Ch is also a C virtual machine. The major difference between Ch and traditional C is that Ch is interpretive in the current implementation. If a program is written in the common set of C and Ch, the program can be executed in the Ch language environment without compilation. At the same time, it can also be compiled in a native C compiler. Many features in C++ are also available in Ch. In addition,
  • Like MATLAB and Mathematica, Ch can be used for rapid prototyping, numerical computing, and visualization.
  • Like Basic, Ch is designed for and has been used by beginners with limited computer experience.
  • Like C shell, Ch can be used as a login shell and for Unix shell programming. But, as a superset of C, Ch is a genuine C shell.
  • Like Perl, Ch can be used for scripting and Common Gateway Interface in web servers.
  • Like Java, Ch can be used for internet computing. A Ch program can be executed across network on different computer platforms on the fly.
  • Like Fortran, Ch can be used for scientific numerical computing.
In this introductory tutorial, some extensions of Ch over C and their applications are highlighted.

Command Mode

Like learning many other languages, let us start Ch programming with a famous programming output statement

hello, world

The amount of effort needed to print out this statement, along with other criteria, is often used to judge the simplicity and friendness of a language. Assume the machine name and current directory is suppressed in a prompt of Unix Shell or MS-DOS shell. To invoke the Ch language environment, just type ch on the terminal keyboard or click the "Ch" icon on the Windows screen. The screen will show the prompt >

This prompt indicates that the program is in the Ch language environment and is ready to accept user's terminal keyboard input. You can also set the Ch-shell as the default shell so that whenever the system is logged in, the Ch language environment will be invoked automatically.

If the input typed in is syntactically correct, it will be executed successfully. Upon the completion of the execution, the monitor prompt > appears again. Otherwise it prints out the corresponding error messages. At the system prompt, any Unix or Windows commands such as cd, ls, pwd, etc. can be executed. In this scenario, Ch is used as a Unix shell in the same manner as Bourne shell, C shell, or Korn shell, MS-DOS command shell.

But, Ch is more powerful in many aspects than these conventional shells. In Ch, if there is any output from the system when executing a command, it will be printed out. In this case, hello world is the output due to the execution of the expression "hello world", which is a string value. If an expression is typed, it will be evaluated by Ch and its result will be printed out immediately. For example, if the expression 1+3*2 is typed, the output will be 7.

> 1+3*2 7 > If the input is 8, the output 8 is the same as the input of 8. Any valid Ch expression can be evaluated in this command mode. Therefore, for novice users, Ch can be used as a calculator.

The first lesson which a C programmer learned may be to use the standard I/O function printf()to get the output hello, world. Since Ch is a superset of C, the function printf() can be executed as follows:

> printf("hello, world");
hello, world
>

No surprise, the system delivered what you expected. Moreover, one can also assign the string to the string variable and then display it by the following code.

> string_t s = "hello, world"  /* declare s as string and do assignment */
> s                                           /* print string value s */
hello, world
>
Like C, the comment of the program in Ch is started by /* and ended with the characters */. Unlike C, statements in Ch can be terminated without a semi-colon. In the above example, once the variable s is assigned with the string value "hello, world", it can also be printed out using the standard I/O function printf() as follows:
>  printf(s)              /* print s value */
hello, world
>

The statement printf(s) is invalid in C. However it is valid in Ch, since Ch is a superset of C. Function printf() is built into Ch. All the functionalities of printf() defined in C are supported in Ch. Many operators and functions defined in C are extended naturally in Ch. For example, the printf() function in Ch is overloaded to support not only formatted output, but also unformatted output as is illustrated in the above code.

You can also easily find the definition or the usage of C/C++/Ch functions in Windows or Unix by the command man from Ch shell. For example, for the C standard function strcpy(), you can run man strcpy.

Note, you can Eenter 'q' to quit the man command or Enter 'b' to go back to the previous page.

> man strcpy STRCPY(3) C/C++ Programmer's Manual STRCPY(3) NAME strcpy, strncpy - copy a string SYNOPSIS #include <string.h> char *strcpy(char *dest, const char *src); char *strncpy(char *dest, const char *src, size_t n); DESCRIPTION The strcpy() function copies the string pointed to by src (including the terminating `\0' character) to the array pointed to by dest. The strings may not overlap, and the destination string dest must be large enough to receive the copy.
Command Files

A C program, also called as a command file, can be executed without compilation in the Ch language environment. In order to run a compiled C program, one has to go through the compilation and link processes to get the executable object code first, and then run the program to get the output. For a large program, the make utility might have to be used to maintain the program's integrity. But, these compilation and link processes are unnecessary for a Ch program since Ch is an interpretive language. For example, if a program print.ch consists of the following statements:

      
      #include<stdio.h>
      int main() {
          printf("hello, world\n");
          return 0;
      }
One can just type the command print.ch to execute the print command to get the output of hello, world as follows:
>  print.ch
hello, world
>
The command line argument interface also follows the C standard.

Ch Professional Edition and Ch Student Edition contain ChIDE, an Integrated Development Environment (IDE) for development of C/Ch/C++ programs as shown below. You can edit, debug or run a program within the IDE with the user interface in over 30 local languages such as German, French, Chinese, and Japanese as shown below. You can set breakpoints, run a porgram step by step, watch and change values of variables during the program execution.

ChIDE edit/run a program


Script Files

Commands can be grouped as a script file in Ch. For example, if the script file test contains the following statements

      int i;
      i = 90;
      cp test test1   /* copy test to test1 */
      printf("i is equal to %d from the script file\n", i);
This script file can be executed interactively as follows:
>  test
i is equal to 90 from the script file
>
After the execution of the script file test, the program test will be copied to a new file named test1.


Function Files

Besides command files and script files, there are function files in Ch. Any standard C function can be treated as a system built-in function. A file whose name ends in ``.chf" such as addition.chf, is treated as a Ch function. The name of the function file and the function definition inside the file must be the same. For example, if a file named addition.chf contains the following statements

      /**** function file for adding two integers ****/
      int addition(int a, int b) {
        int c;
        c = a + b;
        return c;
      }
it can be invoked automatically to add two integers as shown in the following command session.

>  int i = 9;
>  i = addition(3, i);
>  i
12
>
where 3 and 9 are added by the function addition(). The function file addition.chf should be located in a directory pointed by the system variable _fpath which can be changed in the startup file .chrc in Unix and _chrc in Windows in the user's home directory.

More details about how to get it done can be found here.