Zero C# forks bflat to compile C# with no runtime or GC

Zero C# forks bflat to compile C# with no runtime or GC

Zero C# is a project, presented on Show HN, that forks the bflat compiler so that C# compiles straight to a small native program. According to the project page, there is no .NET runtime, no garbage collector and nothing to install where the program runs.

The language mostly stays. Developers keep C# syntax, type checking and generics. Memory comes from arenas that are freed all at once, and a small library supplies strings, collections, input and output on those terms. The page says the compiler still checks everything it checks in .NET; what is missing is what a runtime would do while the program runs.

The sample code on the page shows the style. A 32-character buffer is read into with stackalloc, so nothing is allocated per answer. Output goes through Out.Write, input through In.ReadLine, and strings that must outlive the moment, such as a list of mistakes, are formatted with Str.Format into an arena.

What you keep: C# 15, including unions, extension members and the new memory safety rules; real generics with a specialized copy for each type, plus static abstract members; interfaces and virtual methods, including default interface methods, casts, is and as; records, tuples and anonymous types, with value equality, with and a generated ToString; lambdas and queries such as Where, Select and GroupBy, supplied by a small library instead of LINQ; and threads, where Parallel.For runs a loop on every core.

What you do without: the garbage collector (arenas free their memory all at once, when you say); the .NET runtime itself (hello world is 11 KB on Windows and 40 KB on Linux, with nothing to install); catching exceptions (throw ends the program, and errors are returned as unions); and reflection and async. A type can be compared, but it has no name.

The page then shows one hello-world program built unchanged for five targets, each checked by the same test suite, which requires the same output everywhere. On Linux (x64 or arm64) the result is a native program that needs only the C library; the Minimal binary is 39,848 bytes. On macOS on Apple Silicon, bflat compiles a native Mac program and the Mac's own clang links it, with no container needed to run it; it is 64,728 bytes. On Linux, a macOS build runs in a container. On Windows x64 it is a console program on Windows' own C library, built from Linux or macOS and tested under Wine; Minimal.exe is 10,752 bytes. For WebAssembly it is a WASI module produced through NativeAOT-LLVM that runs under wasmtime; Minimal.wasm is 15,833 bytes. For DOS, the same bitcode is compiled for a 386 and run by the HX DOS extender, tested on Bochs's i386 model. The DIR listing on the page shows PROGRAM.EXE at 16,384, with the unit not given.

The page also lists what works differently without a runtime. Memory is yours to free: there is no garbage collector, so anything made with new is never freed, and arenas hand out memory and free it all at once, one per lifetime. Text avoids throwaway strings: Out.Line formats straight into the output buffer, In.ReadLine reads into a span, and strings that must last go into an arena. Collections (List, Dict, and versions for references and string keys) are all handles into an arena. Finally, every program compiles under the updated memory safety rules: creating a pointer is safe, and reading through one is marked and explained.

For newcomers, the page points to four pages: Install (with dotnet on Linux, or from the repository for every target), Your first program, Run it on DOS (the same program under FreeDOS in an emulator), and a tutorial built as a quiz covering output, input, bad input and arenas. Task guides and a reference of every library type are also linked.

Key facts

  • Zero C# is a fork of bflat that compiles C# to a small native program with no .NET runtime, no garbage collector and nothing to install where it runs.
  • Memory comes from arenas freed all at once, with a small library for strings, collections, input and output; C# 15 features, generics, interfaces, records and Parallel.For stay.
  • Exceptions cannot be caught (throw ends the program, errors are returned as unions), and reflection and async are not available.
  • Hello world is 11 KB on Windows and 40 KB on Linux; the same source also builds for macOS, WebAssembly (WASI) and DOS on a 386, each checked by one shared test suite.

Why it matters

Most C# programs ship with or depend on the .NET runtime and its garbage collector. This project takes the opposite route: it keeps the language and its compile-time checks and drops everything a runtime does while the program runs. The page's headline claim is that a hello-world fits in 11 KB on Windows and 40 KB on Linux, and that one source file reaches five very different targets, from modern desktops to WebAssembly to DOS on a 386.

Who it affects

C# developers who want tiny native binaries, or who want to run C# where a runtime is unavailable or unwelcome, such as WebAssembly modules or very old hardware targets. It also speaks to people interested in arena-style memory management in a language that normally has a garbage collector.

How to use it

The page says to install with dotnet on Linux, or from the repository for every target. Builds use a build.sh script with a program name (for example ./build.sh Minimal) and run.sh to run it. The flags --mac, --win and --wasm select macOS, Windows and WebAssembly. The Windows build can be made from Linux or macOS. The page recommends four starting points: Install, Your first program, Run it on DOS under FreeDOS in an emulator, and a quiz-style tutorial on output, input, bad input and arenas.

How solid is it

The evidence on the page is concrete but limited to hello-world samples: the byte counts for the Minimal program on each target, and a statement that each build is checked by the same test suite, which requires the same output everywhere. The Windows build is tested under Wine, the WebAssembly build runs under wasmtime, and the DOS build is tested on Bochs's i386 model. The page names no author or maintainer, and gives no release date, version number of Zero C# itself, or licence. It gives no speed or memory benchmarks against standard .NET, and no binary-size comparison against regular .NET or standard bflat builds. It does not say which bflat version the fork is based on, or whether the project is production-ready or experimental.

Risks and caveats

The trade-offs are real. Memory is the programmer's job: new is never freed, so lifetimes must be planned around arenas. throw ends the program, so error handling means returning unions. Reflection and async are not available, and LINQ is replaced by a smaller library. The page does not claim that existing .NET libraries or NuGet packages work; a small library replaces strings, collections and LINQ-style queries. Real-hardware testing of the DOS build is not mentioned, and the Windows build is tested under Wine rather than stated as tested on real Windows.

“The compiler still checks everything it checks in .NET. What's missing is what a runtime would do while your program runs.”

— Zero C# project page