logoalt Hacker News

C89cc.sh – standalone C89/ELF64 compiler in pure portable shell

132 pointsby gaigalaslast Wednesday at 8:41 AM34 commentsview on HN

Comments

redohtoday at 10:26 AM

Writing a C compiler in pure shell is one of those projects that sounds absurd until you think about bootstrapping. If you want to compile C on a system where you literally have nothing but a POSIX shell, this is exactly what you need. The fact that the parser itself is BNF-generated from shell modules makes it even more interesting as a study in how far you can push shell scripting before it breaks. Would love to see this evolve into a proper repo with tests so it can actually serve as a minimal bootstrapping tool.

kelsey98765431today at 1:53 AM

Would be a lot better if it came with tests. Please do this justice and dont let it rot as a gist, make a real repo and add some docs and at least smoke tests or some kind. Thanks

show 1 reply
gaigalaslast Wednesday at 8:41 AM

Single standalone file, no external tools used, PATH='' (empty), portable (bash, dash, ksh, zsh), produces x86 ELF executables, has mini-libc builtin.

Usage:

printf 'int main(){puts("hello");return 0;}' | sh c89cc.sh > hello

chmod +x hello

./hello

show 3 replies
ueckertoday at 7:48 AM

I am tempted to click the "report abuse" link ;-)

JackSmith_YCtoday at 5:51 AM

Pure shell. Love the minimalism here... especially when every tiny CLI tool these days seems to require a 50MB node_modules folder just to run. There’s a certain Zen in doing things with zero dependencies. Reminds me of why I got into Unix in the first place.

show 1 reply
_ache_today at 3:23 AM

I'm tempted to execute it, but it may as well be shellcode I couldn't tell.

wengo314today at 9:03 AM

if one could boostrap tcc with it, then it might be a viable tool.

jeytoday at 2:25 AM

It targets x86-64/ELF? I thought it would target `sh` to be portable?

dmeadtoday at 8:35 AM

This is vibe coded right?

dmitrygrtoday at 1:52 AM

Many parts of this are clearly autogenerated, but that in no way diminishes the sickening impressiveness of it!

show 2 replies
self_awarenesstoday at 7:02 AM

"Claude please generate me a C compiler in bash"

I mean, today it's possible to generate it in Tcl, Elisp, Windows BAT, Powershell.

The effort is just 1 prompt.

The WHY question is much more important today -- "because I can" no longer makes sense, because we all can do much, much more with minimum effort today than before LLMs.

show 1 reply