Jump to content

Ch (computer programming): Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
SmackBot (talk | contribs)
m Dated {{No footnotes}}. (Build p609)
Chuser (talk | contribs)
added more links and fixed the links
Line 140: Line 140:
*{{cite journal|last=Campbell|first=Matt|year=2003|title=Ch, A C/C++ Interpreter -- New possibilities for people who like C and Unix|url=http://www.mactech.com/articles/mactech/Vol.19/19.09/CInterpreter/index.html|publisher=MACTECH, the journal of Apple technology}}
*{{cite journal|last=Campbell|first=Matt|year=2003|title=Ch, A C/C++ Interpreter -- New possibilities for people who like C and Unix|url=http://www.mactech.com/articles/mactech/Vol.19/19.09/CInterpreter/index.html|publisher=MACTECH, the journal of Apple technology}}
*{{cite journal|last=Wilson|first=Matthew|year=2004|title=Open-RJ and Ch|url=http://drdobbs.com/184401877?queryText=ChSDK|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Wilson|first=Matthew|year=2004|title=Open-RJ and Ch|url=http://drdobbs.com/184401877?queryText=ChSDK|publisher=Dr. Dobb's Journal}}
*{{cite journal|last1=Wang|first1=Li-rong|last2=Bo|first2=Yo|last3=Hagiwara|first3=I|title=Mobile-C based agent management for collaborative visualization of distributed mesh model|url=http://ieeexplore.ieee.org/search/freesrchabstract.jsp?tp=&arnumber=5375178&queryText%3DMobile-C%26openedRefinements%3D*%26searchField%3DSearch+All|publisher=Computer-Aided Industrial Design & Conceptual Design, 2009. CAID & CD 2009. IEEE 10th International Conference}}
*{{cite journal|last=Huber|first=Tom|year=2010|title=An Introduction to C and Ch: Your One-Stop Shop for Scientific Computing|url=http://www.computer.org/portal/web/csdl/doi/10.1109/MCSE.2010.82
*{{cite journal|last=Huber|first=Tom|year=2010|title=An Introduction to C and Ch: Your One-Stop Shop for Scientific Computing|url=http://www.computer.org/portal/web/csdl/doi/10.1109/MCSE.2010.82
|publisher=IEEE Computing in Science and Engineering}}
|publisher=IEEE Computing in Science and Engineering}}
*{{cite journal|last1=Liu|first1=Li|last2=Wang|first2=Zhaoqing|last3=Jiang|first3=Xusheng|year=2010|title=Anchor-based programming teaching embedded with Ch platform|pages=49-52|url=http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5552033|publisher=Mechatronics and Embedded Systems and Applications (MESA), 2010 IEEE/ASME International Conference}}
*{{cite journal|last1=Liu|first1=Li|last2=Wang|first2=Zhaoqing|last3=Jiang|first3=Xusheng|year=2010|title=Anchor-based programming teaching embedded with Ch platform|pages=49-52|url=http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=5552033|publisher=Mechatronics and Embedded Systems and Applications (MESA), IEEE/ASME International Conference}}
*{{cite journal|last1=Furman|first1=B.|last2=Wertz|first2=E.|year=2010|title=A first course in computer programming for mechanical engineers|pages=70-75|url=http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?reload=true&arnumber=5552091|publisher=Mechatronics and Embedded Systems and Applications (MESA), IEEE/ASME International Conference}}


== Further reading ==
== Further reading ==
Line 148: Line 150:
*{{cite journal|last=Cheng|first=Harry|year=1993|title=Scientific Computing in the Ch Programming Language|pages=49-75|url=http://iospress.metapress.com/content/f225771541203807/|publisher=Scientific Programming}}
*{{cite journal|last=Cheng|first=Harry|year=1993|title=Scientific Computing in the Ch Programming Language|pages=49-75|url=http://iospress.metapress.com/content/f225771541203807/|publisher=Scientific Programming}}
*{{cite journal|last=Cheng|first=Harry|year=1995|title=Extending C and FORTRAN for Design Automation|pages=390-395|url=http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&id=JMDEDB000117000003000390000001&idtype=cvips&gifs=yes&ref=no|publisher=ASME Trans., Journal of Mechanical Design}}
*{{cite journal|last=Cheng|first=Harry|year=1995|title=Extending C and FORTRAN for Design Automation|pages=390-395|url=http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&id=JMDEDB000117000003000390000001&idtype=cvips&gifs=yes&ref=no|publisher=ASME Trans., Journal of Mechanical Design}}
*{{cite journal|last=Cheng|first=Harry|year=1995|title=Extending C with arrays of variable length|pages=375-406|url=http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B6TYV-3Y6PCHF-V&_user=10&_coverDate=09%2F15%2F1995&_rdoc=1&_fmt=high&_orig=gateway&_origin=gateway&_sort=d&_docanchor=&view=c&_searchStrId=1681696907&_rerunOrigin=google&_acct=C000050221&_version=1&_urlVersion=0&_userid=10&md5=3ff9d5a72bff0ab257335bc042261ca4&searchtype=a|publisher=Computer Standards & Interfaces}}
*{{cite journal|last=Cheng|first=Harry|year=1995|title=Extending C with arrays of variable length|pages=375-406|url=http://www.sciencedirect.com/science?_ob=ArticleURL&_udi=B6TYV-3Y6PCHF-V&_user=10&_coverDate=09%2F15%2F1995&_alid=1737140035&_rdoc=1&_fmt=high&_orig=search&_origin=search&_zone=rslt_list_item&_cdi=5628&_sort=r&_st=13&_docanchor=&view=c&_ct=1&_acct=C000050221&_version=1&_urlVersion=0&_userid=10&md5=1369ffa56fdef3033135fa8fc1eb4c15&searchtype=a|publisher=Computer Standards & Interfaces}}
*{{cite journal|last=Cheng|first=Harry|year=2002|title=C99 & Numeric Computing|pages=28-34|url=http://drdobbs.com/cpp/184404993|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Cheng|first=Harry|year=2002|title=C99 & Numeric Computing|pages=28-34|url=http://drdobbs.com/cpp/184404993|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Cheng|first=Harry|year=2006|title=Ch: A C/C++ Interpreter for Script Computing|pages=6-12|url=http://drdobbs.com/184402054|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Cheng|first=Harry|year=2006|title=Ch: A C/C++ Interpreter for Script Computing|pages=6-12|url=http://drdobbs.com/184402054|publisher=Dr. Dobb's Journal}}
*{{cite journal|last1=Wang|first1=Zhaoqing|last2=Cheng|first2=Harry|year=2006|title=Portable C/C++ Code for Portable XML Data|pages=76-81|url=http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=1576661|publisher=IEEE Software}}
*{{cite journal|last=Cheng|first=Harry|year=2009|title=Speeding-Up Software Development Using Embedded Scripting|pages=8-8|url=http://drdobbs.com/architecture-and-design/212201774|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Cheng|first=Harry|year=2009|title=Speeding-Up Software Development Using Embedded Scripting|pages=8-8|url=http://drdobbs.com/architecture-and-design/212201774|publisher=Dr. Dobb's Journal}}
*{{cite journal|last=Cheng|first=Harry|year=2009|title=C for the Course|pages=50-52|url=http://memagazine.asme.org/Articles/2009/september/C_Course.cfm|publisher=ASME Mechanical Engineering Magazine}}
*{{cite journal|last=Cheng|first=Harry|year=2009|title=C for the Course|pages=50-52|url=http://memagazine.asme.org/Articles/2009/september/C_Course.cfm|publisher=ASME Mechanical Engineering Magazine}}
Line 158: Line 159:
== External links ==
== External links ==
* [http://www.softintegration.com SoftIntegration Home Page]
* [http://www.softintegration.com SoftIntegration Home Page]
* [http://www.mobilec.org/ Mobile-C: a Multi-Agent Platform for Mobile C/C++ Agents Home Page]
* [http://www.softintegration.com/demos/chstandard/c99.html C99 features in Ch]
* [http://www.softintegration.com/demos/chstandard/c99.html C99 features in Ch]
* [http://www.softintegration.com/docs/ch/shell/ Ch Shell]
* [http://www.softintegration.com/docs/ch/shell/ Ch Shell]

Revision as of 04:22, 2 May 2011

Ch (/[invalid input: 'icon']ˌsˈ/) is a cross-platform C and C++ interpreter originally designed by Dr. Harry H. Cheng as a scripting language for beginners to learn math, computing, numerics, and programming in C/C++.

Now developed by SoftIntegration, Inc., Ch is written in C and runs under Windows, Linux, Mac OS X and some versions of Unix. It supports C90 and major C99 features, but it does not support the full set of C++ features. C99 complex number and VLA features were supported in Ch before they became part of the C99 standard. Ch can also be run as a interactive shell to execute C statement, C script file, Unix commands, and Windows commands (under windows only).

Features

C/C++ interpreter

Ch supports the 1999 ISO C Standard (C99) and C++ classes. It is a superset of C with C++ classes. C99 major features such as complex numbers, variable length arrays (VLAs), IEEE-754 floating-point arithmetic and generic mathematical functions are supported. Wide characters in Addendum 1 for C90 is also supported.

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
  • Const member functions
  • The new and delete operators
  • Constructors and destructors
  • 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

Embeddable scripting

As a C/C++ interpreter, Ch can be used as a scripting engine for your applications. The pointer to array or variables can be passed and shared in both binary C space and ch scripting space. It extends your applications with a C compatible scripting language.

Shell programming and cross-platform scripting

Ch is a C-compatible shell similar to C-shell (csh). It can be used as login shell. Ch has a built-in string type for automatic memory allocation and de-allocation. It supports shell alias, history, filename wildcarding, piping and iteration etc.

2D/3D plotting and numerical computing

Ch has built-in 2D/3D graphical plotting features and computational arrays for numerical computing. A 2D linear equation of the form b = A*x can be written verbatim in Ch.

Examples

"Hello, world!" in Ch

There are two ways to run Ch code. One is:

   printf("Hello world!\n");

Another is:

   #include <stdio.h>
   int main() {
       printf("Hello world!\n");
   }

Ch also supports interactive shell command and C statements.

 > int i, *p, **p2     // i is an integer, p pointer, p2 double pointer
 > i=10                // i is assigned value 10
   10
 > p=&i                // p points to address of i
   00D847C0
 > *p                  // the memory pointed by p has value 10
   10
 > p2=&p               // p2 points to address of p
   00D84D30
 > **p2                // the memory pointed by the pointer at p2 has value 10
   10
 >

Numerical computing in Ch

   #include <stdio.h>
   #include <array.h>
   int main() {
       array double A[2][3] = {1, 2, 3,
                           4, 5, 6};
       array double B[3][2];
       printf("A= \n%f \n", A+A);
       B = 2*transpose(A);
       printf("B= \n%f \n", B);
   }

The output is:

   A=
   2.000000 4.000000 6.000000
   8.000000 10.000000 12.000000
   B=
   2.000000 8.000000
   4.000000 10.000000
   6.000000 12.000000

Shell programming

Find and compile all .c files into .o in the current directory for which the .o file is old or absent:

   #!/bin/ch
   #include <sys/stat.h>
   struct stat cstat, ostat;
   string_t c, o;
   foreach (c; `find . -name "*.c"`)
   {
       o=`echo $c | sed 's/.c$/.o/'`;
       stat(o, &ostat); stat(c, &cstat);
       if (ostat.st_mtime > cstat.st_mtime)
       {
           echo "compiling $c to $o";
           gcc -c -o "$o" "$c";
       }
   }

2D/3D plotting in Ch

To plot a sine wave:

  #include <math.h>
  #include <chplot.h>
  int main() {
       int numpoints = 36;
       array double x[numpoints], y[numpoints];
       linspace(x, 0, 360); // assign x with values from 0 to 360 linearly
       y = sin(x*M_PI/180);
       plotxy(x, y, "Ch plot", "xlabel", "ylabel");
   }

See also

References

  • Heller, Martin (2001). "The Ch Language Environment". Byte Magazine. {{cite journal}}: Cite journal requires |journal= (help)
  • Glassborow, Francis (2001). "The Ch Language Environment Version 2.0". C Vu Magazine: 36–37. {{cite journal}}: Cite journal requires |journal= (help)
  • Wang, Gary (2002). "Ch Solves Portability Headaches". IEEE Spectrum. {{cite journal}}: Cite journal requires |journal= (help)
  • Campbell, Matt (2003). "Ch, A C/C++ Interpreter -- New possibilities for people who like C and Unix". MACTECH, the journal of Apple technology. {{cite journal}}: Cite journal requires |journal= (help)
  • Wilson, Matthew (2004). "Open-RJ and Ch". Dr. Dobb's Journal. {{cite journal}}: Cite journal requires |journal= (help)
  • Wang, Li-rong; Bo, Yo; Hagiwara, I. "Mobile-C based agent management for collaborative visualization of distributed mesh model". Computer-Aided Industrial Design & Conceptual Design, 2009. CAID & CD 2009. IEEE 10th International Conference. {{cite journal}}: Cite journal requires |journal= (help)
  • Huber, Tom (2010). "An Introduction to C and Ch: Your One-Stop Shop for Scientific Computing". IEEE Computing in Science and Engineering. {{cite journal}}: Cite journal requires |journal= (help)
  • Liu, Li; Wang, Zhaoqing; Jiang, Xusheng (2010). "Anchor-based programming teaching embedded with Ch platform". Mechatronics and Embedded Systems and Applications (MESA), IEEE/ASME International Conference: 49–52. {{cite journal}}: Cite journal requires |journal= (help)
  • Furman, B.; Wertz, E. (2010). "A first course in computer programming for mechanical engineers". Mechatronics and Embedded Systems and Applications (MESA), IEEE/ASME International Conference: 70–75. {{cite journal}}: Cite journal requires |journal= (help)

Further reading