Hacker News new | ask | show | jobs
by richardwhiuk 1157 days ago
It adds a new dependency - the c language frontend - aka clang - surely the zig compiler emits LLVM IR, not C code?
2 comments

zig supports importing C headers via the special built-in `@cImport`. That feature requires a C language front end to operate. https://ziglang.org/documentation/0.10.1/#Import-from-C-Head...
Zig has a C backend that supports something like 99% of all Zig if I'm remembering the number correctly.

Zig has almost completely solved the bootstrap problem.

This isn't quite correct. Yes, it can output C code; however the result is not very readable at all, and fails the DFSG on generated code. It _is_ useful for compiling Zig code to targets which aren't supported by LLVM, however.
Do you have a reference for this? Does it use a C backend that is part of LLVM, or is it something Zig-specific? What are its limitations? Can it compile libraries to C, or only entire applications?

I have wanted Rust and Zig to support compile-to-C for a while, so this is exciting news for me.

One thing that would particularly interest me is if functions intended to be inlined could be emitted into .h files.