explaingit

orangeduck/cello

7,118CAudience · developerComplexity · 3/5Setup · moderate

TLDR

Cello is a C library that adds generics, garbage collection, exceptions, and object-like method dispatch to plain C, letting you write higher-level code without switching languages.

Mindmap

mindmap
  root((cello))
    What it does
      Generic containers
      Garbage collection
      Exception handling
      Method dispatch
    Tech Stack
      C language
      Fat pointers
    Use Cases
      Personal experiments
      Systems learning
    Audience
      C developers
      Language explorers
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

Add generic containers and foreach loops to an existing C project without rewriting it in C++.

USE CASE 2

Experiment with automatic memory management in C by letting Cello clean up allocated objects instead of tracking every free() call.

USE CASE 3

Use Cello as a teaching tool to understand how runtime type information and method dispatch work at the C level.

Tech stack

C

Getting it running

Difficulty · moderate Time to first run · 30min

Requires a C compiler and make, the author recommends testing on personal projects only due to known quirks.

In plain English

Cello is a library for the C programming language that adds features normally found in higher-level languages. C is fast and widely used, but it lacks built-in support for things like generic containers that hold any type of data, automatic memory cleanup, error handling via exceptions, and object-like behavior where the same function name works differently depending on the type it receives. Cello adds all of these on top of standard C. With Cello you can create arrays and tables that hold typed values, loop over collections with a foreach keyword, and define custom types that can be compared, printed, and hashed without writing that logic from scratch each time. Optional garbage collection means you can allocate objects and let Cello clean them up automatically when they go out of scope, rather than tracking every free() call manually. The library works by attaching type information to pointers at runtime, a technique the author describes as a fat pointer approach. This lets functions inspect what type of object they received and dispatch behavior accordingly, similar to how object-oriented languages handle method calls. Existing C structs can be registered with Cello to gain these abilities without rewriting them. The author is clear that Cello started as an experiment to see how far C could be pushed, and recommends trying it on a personal project before anything production-facing. The README notes that the library has quirks and that teams working under deadlines would find better tooling and community support in C++ instead. The source code and documentation are available, and contributions are welcome. The author also links to a book they wrote on building a Lisp interpreter in C.

Copy-paste prompts

Prompt 1
Show me how to create a generic List in Cello that holds integers, then iterate over it with foreach and print each value.
Prompt 2
How do I register my existing C struct with Cello so it supports comparison, printing, and hashing without writing that logic from scratch?
Prompt 3
Write a small Cello program that allocates objects and relies on garbage collection to clean them up automatically when they go out of scope.
Prompt 4
Explain the fat pointer technique Cello uses to attach type information to pointers at runtime and how it enables method dispatch.
Prompt 5
What are the known quirks and limitations of Cello I should be aware of before using it in a project?
Open on GitHub → Explain another repo

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

Verify against the repo before relying on details.