explaingit

rswier/c4

10,687CAudience · developerComplexity · 2/5Setup · easy

TLDR

c4 is a minimalist C compiler and interpreter written in just four C functions, a programming curiosity that can even interpret its own source code.

Mindmap

mindmap
  root((c4))
    What it does
      C compiler in C
      Interpreter runtime
      Self-hosting demo
    Minimalism
      Four functions only
      No dependencies
      Tiny codebase
    Learning value
      Compiler internals
      Parser design
      VM concepts
    Usage
      Compile with gcc
      Run C source files
      Run itself
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Compile and run c4 to understand how a minimal compiler works at a fundamental level using only four functions.

USE CASE 2

Use c4 as a learning reference to study how parsing and execution can be done in under a few hundred lines of C.

USE CASE 3

Run c4 on its own source code to see a self-hosting interpreter in action.

Tech stack

C

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

c4 is described as "C in four functions" and is explicitly called an exercise in minimalism. The entire project is a C compiler and interpreter, written in the C programming language itself, using only four functions to accomplish the job. The README is intentionally sparse. It shows how to compile the project with a standard C compiler, then run it to interpret a C source file. You can also pass the c4 interpreter to itself, meaning the interpreter can run its own source code, which is a classic demonstration of self-hosting in programming language tools. Because the README provides very little detail beyond the build and run commands, the scope of supported C features, any known limitations, and the intended audience are not described. The project appears aimed at programmers curious about how compilers work at a fundamental level, or those interested in how much can be done with very little code.

Copy-paste prompts

Prompt 1
Walk me through the c4 source code and explain how each of the four functions works and how they chain together to compile and run C code.
Prompt 2
I want to understand how c4 implements its virtual machine. Explain the instruction set and execution loop in the source.
Prompt 3
How does c4 achieve self-hosting, running its own source file as input? Trace through what happens step by step.
Open on GitHub → Explain another repo

← rswier on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.