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

https://news.ycombinator.com/rss Hits: 9
Summary

#!/bin/sh # ISC License # Copyright (c) 2026 Alexandre Gomes Gaigalas <alganet@gmail.com> # Permission to use, copy, modify, and/or distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # ============================================================ # c89cc — standalone C89 parser + compiler (x86-64 ELF64) # ============================================================ # # Usage: # sh c89cc.sh < prog.c > a.out # sh c89cc.sh --no-libc < prog.c > a.out (skip built-in libc) # --- core/header.sh --- set -euf LC_ALL=C IFS='' _EOL=' ' _TAB=" " # Clear PATH: no external commands needed PATH= # Shell compat: aliases in bash, POSIX-like in zsh shopt -s expand_aliases >/dev/null 2>&1 || : setopt sh_word_split null_glob glob_subst \ no_glob no_multios no_equals 2>/dev/null || : # ksh/mksh fallback: 'local' may not exist, use 'typeset' instead command -v local >/dev/null 2>&1 || alias local=typeset >/dev/null 2>&1 || : # Fallback: if 'test' is not a builtin, wrap it via command -p if ! command -v test >/dev/null 2>&1; then test () { command -p test "$@"; }; fi # --- Output helpers --- # Detect best available output primitive: # printf > print > echo > command -p printf # _printn1: print string without newline _printr1: print string with newline if command -v printf >/dev/null 2>&1 then _printn1 () { printf '%s' "$1"; } _printr1 () { printf '%s\n' "$@"; } elif command -v p...

First seen: 2026-04-03 02:06

Last seen: 2026-04-03 10:10