BetterC and Bare-Metal D
35.1 -betterC
BetterC = D without the D runtime: no GC, no exceptions (by default), no TypeInfo-dependent features, no module constructors, no dynamic array appends or associative arrays.
What remains: templates, CTFE, mixins, slices, structs with destructors, scope(exit), ranges (non-allocating), static foreach, UFCS, @safe, contracts/asserts.
Use cases: embedding D into C projects, kernels, microcontrollers, WebAssembly, writing C libraries in D.
// app.d (compile: dmd -betterC app.d / ldc2 -betterC app.d)
import core.stdc.stdio : printf;
extern(C) int main()
{
int[5] arr = [1, 2, 3, 4, 5];
foreach (x; arr) printf("%d ", x);
printf("\n");
return 0;
}35.2 Bare Metal and Embedded
Volatile MMIO with core.volatile (volatileLoad/volatileStore). Custom object.d for minimal runtimes. Linker scripts. Projects: PowerNex (OS), Tilix (GTK terminal, not embedded), LWDR (lightweight D runtime for microcontrollers), and the dlang-on-arm projects.
ldc2 -betterC -mtriple=thumbv7em-none-eabihf -mcpu=cortex-m4 -O -c firmware.d
ldc2 -mtriple=wasm32-unknown-unknown-wasm -betterC -L-allow-undefined lib.d # WebAssembly