Tuesday, 24 November 2026

Trusted News Discovery โ€“ Powered by AI and Verified by Humans

Type-C adds variants, generics and pattern matching to the C language, one renamed file at a time

Type-C, an open-source project by Stanislav Sedov, adds variants, generics, pattern matching and error values to C11 while compiling to plain C.

Produced with AI assistance and reviewed by the Badiyaa Editorial Desk. How we work.

Grok Fact CheckCheck it yourself in one tapVerify with Grok ↗Ask @grok on X ↗
A laptop and a coffee mug sit on a table.
Image: Ryan Riggins, CC0 via Wikimedia Commons

Type-C, a new open-source tool from developer Stanislav Sedov, bolts variants, generics, pattern matching and error values onto the C programming language without asking anyone to leave C behind. Rename one .c file to .tc, and the rest of the program can stay exactly as it is.

Sedov showed the project on Hacker News this week, writing that he loves C but that parsing, tree-walking and complex error handling in it often turn into "spaghetti code." Type-C's GitHub page sums up the idea as C11 "with the types C is missing."

How it works

Type-C does not replace your compiler. Its own compiler, typec, accepts the same command-line options as the standard cc command, translates the Type-C parts into ordinary, readable C, and then passes that C to GCC or Clang. Because every valid C11 file is already a valid Type-C file, a team can adopt it one file at a time. Sedov compared the approach to TypeScript, which layers types over JavaScript.

The additions, in brief:

  • Variants and match: a value is exactly one of a fixed set of cases, and the compiler refuses to build if a match statement forgets one.
  • Distinct types: ids and units that cannot be swapped by accident.
  • Generics: types and functions that work across many element types.
  • Errors as values: a result type with try, which passes an error up at once, and defer, which schedules cleanup.

There is no runtime, garbage collector or extra library added to the program, the project says, which is why Sedov pitches it for kernel and bare-metal code too.

The numbers behind the pitch

As a test, the project rewrote the parser of tomlc99, a C library for reading TOML configuration files, using result, try and defer. Under fault injection, which forces memory allocations to fail one at a time, the original C code misbehaved in 34 of 1,416 runs (25 memory leaks and 9 uses of freed memory), while the rewrite had none. Speed matched a hand-written C version within measurement noise, and the compiled code was 2.8% larger with Clang and 11.9% larger with GCC.

The README is candid that the tools did not fix the bugs by themselves: the rewrite still needed its steps reordered to remove the use-after-free cases. It is also clear that Type-C is not memory safe in the way safe Rust or OCaml are.

Why C still needs this

C has changed slowly. The C11 standard, which Type-C builds on, was published by ISO on December 8, 2011, according to Wikipedia's entry on C11, and added features such as type-generic expressions and threads but no checked variants. Languages like Rust and Zig offer those, but adopting them means new toolchains and bindings at the border with existing C code.

Badiyaa has followed the same tension in the C++26 standard's second finish, the rush of new Rust GUI toolkits and Elixir HLS turning code into chip circuits.

What is next

Type-C 1.0's core language is frozen, and its test suite passes on GCC and Clang on macOS and Linux. Still unbuilt is a "checked mode" meant to rule out specific classes of memory errors, listed as the next stage of the project's plan. It installs today through Homebrew under the BSD-2-Clause license.

Sources

Image: Ryan Riggins, CC0 via Wikimedia Commons

This article was produced with AI assistance and reviewed by our Editorial Desk. How we work.

Grok Fact CheckCheck it yourself in one tapVerify with Grok ↗Ask @grok on X ↗