tinycc-mirror-repository: TinyCC: The One-Pass Miracle

How Fabrice Bellard turned the world's most formidable systems language into a 100KB scripting engine.

Tiny-C-Compiler/tinycc-mirror-repository

A massive, complex clockwork machine representing GCC being bypassed by a small, sleek aerodynamic needle representing TCC, which is sewing a thread through a series of punch cards.
TCC bypasses the complex machinery of modern compilers to stitch code directly into execution.

Key Takeaways

C as a Scripting Language

C is a compiled language. You write, you build, you link, and eventually, you run. The Tiny C Compiler shatters this cycle.

#!/usr/local/bin/tcc -run
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

C script supported : just add '#!/usr/local/bin/tcc -run' at the first line of your C source, and execute it directly from the command line.

With a simple shebang, TCC executes C source files as if they were Python or bash scripts. There is no perceivable lag. The edit-compile-run loop becomes instantaneous.

The Streaming Compiler

Modern compilers like GCC and Clang are behemoths. They parse code into massive Abstract Syntax Trees, run dozens of optimization passes, and eventually emit assembly. TCC treats compilation as a streaming problem.

It uses a one-pass architecture. As the lexer reads tokens, the generator immediately emits machine code. There is no AST. There are no heavy intermediate representations.

TCC's one-pass architecture bypasses the Abstract Syntax Tree entirely, emitting machine code as it parses tokens.

Libtcc: The JIT in Your Pocket

TCC is not just a standalone executable. It is a library.

It's not just a tiny C compiler - it's a compiler you can use as a static library that can compile your C code directly to memory. And then you can call into it, if you dare.

fwsgonzo, Hacker News Commenter · Tiny C Compiler | Hacker News

Developers embed libtcc to give their C programs a Just-In-Time compiler. You can generate code strings dynamically, compile them into memory, and execute them on the fly.

The Efficiency Frontier

TCC does not optimize code. The resulting binaries execute slower than those produced by GCC with heavy optimization. But the compilation speed is unmatched.

Compiles and links about 10 times faster than 'gcc -O0'.

CompilerArchitectureCompilation SpeedOptimization
TCCOne-Pass, No ASTExtremely Fast (~10x GCC)Minimal
GCCMulti-Pass, Heavy ASTBaselineExtensive (O1-O3)
ChibiccEducational, IncrementalModerateNone

The Bootstrapping Anchor

Because of its tiny footprint, TCC is a favorite tool for bootstrapping systems from source. It can compile the Linux kernel in seconds.

TCC can of course compile itself.

This self-hosting capability makes it a crucial link in creating fully auditable software stacks. It proves that a complete, capable C compiler can fit inside a 100KB executable.