« CBL RememberMe | Main | C - 0.02 »

C - a pseudo-interpreter of the C programming language

In order to write one-liners in C, I created a tiny wrapper for GCC.

C (pronounced large-C) is a pseudo-interpreter of the C programming language.

Without the need of manual compilation, developers can rapidly create scripts or write one-liners using the C programming language that runs at native-code speed.

C, the pseudo-interpreter, has several advantages over other scripting languages, such as perl.

  • very fast (100x faster than perl when calculating fib(40))
  • easy handling of binary data
  • good for testing system calls and C APIs


To install,copy the downloaded file to /usr/bin, and chmod 755.

Below are some examples.

% C -e 'printf("hello world\n")'
hello world

% C -cO3 -e 'int fib(int i) { return i > 2 ? fib(i-1) + fib(i-2) : 1; } printf("%d\n", fib(40))'
102334155

% C -e 'int t, sum = 0; while (fread(&t, sizeof(int), 1, stdin) == 1) sum += t;printf("%d", sum)' < data
31289

% cat hello.C
#! /usr/bin/C

printf("hello world\n");

% ./hello.C
hello world

For the newest information of the C interpreter, see C Archives.

TrackBack

Listed below are links to weblogs that reference C - a pseudo-interpreter of the C programming language:

» C - 0.02 from Kazuho at Work
C - a pseudo-interpreter of the C programming language has now been updated to version 0.02. Download: http://labs.cybozu.co.jp/blog/kazuho/archives/c/C-0_02 To install, cp C-0_02 /usr/bin/C && chmod 755 /usr/bin/C. Following features have been added: ... [Read More]

Comments

I wonder how this compares to Inline::CPR. Maybe soon I'll have some time to compare them myself...

The only reason I used perl to implement the initial version of large-C, is that it was easier for me than using C to do so. Although Inline::CPR do look very interesting, I do not have any intension to adding that kind of rich features to large-C.

My current interest is in re-implementing large-C in C, so that I can execute large-C itself in large-C... :-p

I wonder if you've seen CINT by Masaharu Gotoh. If you just need a C/C++ interpreter to embed into an application, that already does what you want. If this is for 'self education' or for fun, then never mind.

CINT is used in a very large-scale project called Root at the international high energy physics lab CERN. Root is a framework for analyzing high energy physics data.

While Gotoh-san wrote CINT while working for H.P. Japan, maintenance and development of CINT has been taken over by Rene Brun's group at CERN and can be gotten at:
http://root.cern.ch/root/Cint.html

Ron Fox (fox at nscl dot msu dot edu
NSCL
Michigan State University
East Lansing, MI 48824-1321

[Unix] is not necessarily evil, like OS/2. - Peter Norton

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)