C extensions, portability challenges with alternative compilers
Original: C extensions, portability, and alternative compilers
Why This Matters
Highlights fundamental portability challenges limiting C compiler ecosystem diversity
Developer working on C compiler highlights portability issues with glibc headers and system libraries. GNU libc's sys/cdefs.h only recognizes GCC, clang, and TCC compilers, breaking compatibility with alternative compilers despite attempts at portability.
A C compiler developer documents compatibility challenges when implementing non-GCC compilers on GNU/Linux systems. The main obstacle is glibc headers, particularly sys/cdefs.h, which attempts compiler detection but fails for alternative compilers. For example, struct epoll_event requires __attribute__((packed)) support for correct ABI, but glibc defines attributes away for unrecognized compilers. The code explicitly checks for __GNUC__, __clang__, or __TINYC__ macros, ignoring other compilers. Similar issues exist with compiler-provided headers like stddef.h and limits.h, where glibc's limits.h assumes GCC-specific behavior and uses #include_next directives. These compatibility layers, while intended to support various environments through preprocessor guards, often break when encountering truly alternative compiler implementations.