Writing a C compiler that works with real-world codebases is far harder than implementing the ISO standard, because most C code relies on GCC/clang-specific extensions and non-standard behaviors. The author documents concrete obstacles encountered while building their own C compiler: glibc headers that only recognize GCC, clang, and TCC via __attribute__ guards; limits.h depending on GCC's #include_next extension; SDL_endian.h's broken feature detection that assumes GCC-style inline assembly; OpenBSD's __only_inline macro that breaks non-GNU compilers; and Android's bionic libc assuming clang. The post concludes with four strategies for alternative compiler authors: upstream patches, gaining popularity, maintaining downstream patches, or pretending to be GCC (as clang does by defining __GNUC__=4). The author advocates for wider use of feature test macros like __has_builtin instead of compiler-specific guards.

9m read timeFrom lemon.rip
Post cover image
Table of contents
On C extensions, portability, and alternative compilersglibcSDLOpenBSD libcbionicConclusion: it is what it is var s=["it is what it is","éche o que hai","c'est la vie","しょうがない", "è così"]; document.write(s[(Math.random()*s.length)|0]); it is what it is

Sort: