Show HN: My C compiler compiled itself

Overall reaction and project scope

  • Many comments express admiration and excitement about a small, self-hosting C compiler.
  • The author says it supports roughly “70% of C”, intentionally omitting floats, arrays, and some features to keep it small and self-hosting.
  • They report learning that writing a C compiler is “not that hard, just time-consuming.”

Build system: Makefile vs Python

  • A major subthread debates why bootstrapping (multi-stage build) is done via build.py instead of Make.
  • One side argues Makefiles are simple, concise, readable, and provide incremental builds “for free”.
  • Others counter that Make is unfamiliar, idiosyncratic, or non-intuitive to people from other language ecosystems; Python can be more approachable.
  • There is a detailed mini-tutorial on Make syntax, targets, dependencies, and automatic variables like $@ and $<.
  • Further discussion highlights issues around header dependencies, incremental correctness, and when Make becomes too complex; some suggest alternatives (ninja, custom tools).

Bootstrapping and self-hosting rationale

  • One thread explains classic compiler bootstrapping: implement new features without using them, then reimplement using the new features, repeating iteratively.
  • Discussion on “full bootstrapping” ranges from starting in assembly or even raw machine code to practical approaches today (cross-compiling, using higher-level languages).
  • The author notes the third compilation stage is to validate that code generation from the stage-2 compiler is correct on a nontrivial project.
  • Another commenter expands: stage 3 is useful to catch miscompilation bugs; comparing stage-2 and stage-3 outputs can reveal errors.

C style, type system limitations, and tone

  • A suggestion is made to avoid casting malloc and use sizeof *ptr for DRYness and safety.
  • The author replies their compiler currently can’t handle that sizeof *ptr form correctly and is stricter than standard C regarding void* conversions.
  • This leads to debate about whether the style advice and its tone were appropriate; some find it helpful and educational, others see it as condescending or unnecessary.
  • There is side discussion on sizeof behavior, type safety, and C vs C++ compatibility.

Other technical side threads

  • Brief discussion of WASM as a bootstrap target; one commenter argues WASM’s control-flow constraints make it a poor target for simple single-pass C compilers.
  • Questions about whether binaries from a gcc-built 30cc and a self-hosted 30cc would be identical; conclusion: they should match if codegen is deterministic, but guarantees are nuanced.
  • Multiple references point to “bootstrappable builds” projects as thematically related.