Tiny C Compiler, usually called TCC, is a very small C compiler available on both Windows and Linux. Even though the compiler itself is under 100 KB, it handles the full path from preprocessing and compilation to assembly generation and linking. It is also known for compiling faster than gcc, supports ISO C99, includes some memory and array bounds checking, and is even capable of building the Linux kernel.
That alone makes it an impressive tool, but the most intriguing part is not its size. TCC can run ANSI C source files directly in the same spirit as a scripting language on Unix systems, using a shebang such as #!/usr/bin/tcc. Instead of compiling and linking by hand at the command line, you can execute a C source file directly.
That changes the feel of the language quite a bit. C stops looking like something that always needs a traditional build step and starts behaving more like Perl or Python for quick tasks. Being able to use C in a script-like way, almost as casually as writing a shell script, is a surprisingly interesting idea by itself.
And TCC does not stop there.
A good example of what this tiny compiler enables is the open-source project C in Python:
http://www.cs.tut.fi/~ask/cinpy/
The idea behind Cinpy is simple: it lets you use C source code directly inside Python. Rather than calling precompiled C functions through a shared library, you can define C functions inside a Python module itself.
This makes it different from the more familiar approach of connecting Python to C through dynamic libraries. With Cinpy, the C code is written inline and turned into callable functions from within Python.
Here is the example shown below:
import ctypes
import cinpy
# Fibonacci in Python
def fibpy(x):
if x<=1: return 1
return fibpy(x-1)+fibpy(x-2)
# Fibonacci in C
fibc=cinpy.defc("fib",
ctypes.CFUNCTYPE(ctypes.c_long,ctypes.c_int),
"""
long fib(int x) {
if (x<=1) return 1;
return fib(x-1)+fib(x-2);
}
""")
# ...and then just use them...
# (there _is_ a difference in the performance)
print fibpy(30)
print fibc(30)
In this snippet, one Fibonacci function is written in Python and the other in C, but both are used from the same Python program. The performance difference is the whole point: TCC makes this kind of hybrid workflow lightweight enough to be practical.
Cinpy source package:
cinpy-0.10.tar.gz