Show HN: Zero C#,无 GC 的 C# 强大功能
Show HN: Zero C# – C# without a runtime or GC

原始链接: https://onurgumus.github.io/zero-csharp/index.html

未修改的 hello-world 示例为多个目标构建,并由同一测试套件验证,输出一致。Linux x64/arm64 生成仅依赖 C 库的 39,848 字节原生二进制;macOS 通过 bflat 和 clang 生成 64,728 字节的 Apple Silicon 原生二进制,无需容器;Windows x64 生成 10,752 字节的控制台可执行文件,并在 Wine 下测试;WebAssembly 生成 15,833 字节的 WASI 模块,由 wasmtime 运行;386 上的 DOS 生成 16,384 字节可执行文件,通过 HX DOS extender 运行。每个目标都展示了跨平台编译,同时保留相同的“Hello from zero-mode!”输出。

Show HN 介绍了 Zero C#,描述为在无任何垃圾回收的情况下提供 C# 的能力。评论者讨论内存管理:有人更偏好 arena 分配器,但认为像 Swift 那样的引用计数更适合 C#;另一人担心垃圾堆积并询问 GUI 库;回复澄清内存来自 arena,一次性释放。其他人将其与 Beef 比较,并 jokingly 称它终于成了 C--。
相关文章

原文

The hello-world sample, unchanged, built for each target. Each build is checked by the same test suite, which requires the same output everywhere.

$ ./build.sh Minimal
$ ./run.sh Minimal
Hello from zero-mode!
$ wc -c bin/Minimal
39848 bin/Minimal

Linux, x64 or arm64

A native program that needs only the C library. On macOS it builds and runs in a container.

$ ./build.sh --mac Minimal
$ bin/mac/Minimal
Hello from zero-mode!
$ wc -c bin/mac/Minimal
64728 bin/mac/Minimal

macOS on Apple Silicon

A native Mac program: bflat compiles it, the Mac's own clang links it. No container to run it.

$ ./build.sh --win Minimal
$ ./run.sh --win Minimal
Hello from zero-mode!
$ wc -c bin/win/Minimal.exe
10752 bin/win/Minimal.exe

Windows x64

A console program on Windows' own C library, built from Linux or macOS. Tested under Wine.

$ ./build.sh --wasm Minimal
$ ./run.sh --wasm Minimal
Hello from zero-mode!
$ wc -c bin/wasm/Minimal.wasm
15833 bin/wasm/Minimal.wasm

WebAssembly

A WASI module, through NativeAOT-LLVM. Runs under wasmtime.

C:\>D:
D:\>PROGRAM
Hello from zero-mode!

D:\>DIR PROGRAM.EXE
PROGRAM  EXE     16,384

D:\>

DOS on a 386

The same bitcode compiled for a 386, run by the HX DOS extender. Tested on Bochs's i386 model.

联系我们 contact @ memedata.com