HeadlinesBriefing favicon HeadlinesBriefing.com

C Compiler Portability: Non-Standard Extensions Break Toolchains

Hacker News •
×

Writing C that actually adheres to the ISO standard is an impractical goal for most developers. Real-world codebases rely on compiler extensions and non-standard behaviors just to compile, and a developer building their own C compiler catalogued the portability headaches they hit across glibc, SDL, and OpenBSD headers.

glibc headers assume GNU extensions to function. sys/cdefs.h wraps features in preprocessor guards that exclude anything outside GCC, clang, or TCC. Struct epoll_event needs __attribute__((packed)), but omitting it breaks the ABI on 64-bit systems. Even builtin headers like limits.h depend on #include_next and GCC-specific macros to define POSIX constants correctly.

SDL_endian.h checks for GCC or clang first, then falls back to ISA-specific macros and inline assembly, skipping builtins on non-GNU compilers. OpenBSD libc uses __only_inline, which assumes GCC inline semantics and breaks on other compilers. The _ANSI_LIBRARY macro provides a workaround by disabling these definitions.