C's Flexible Integer Sizes Were Not a Design Mistake
C's flexible integer sizes were a deliberate 1970s design choice for cross-architecture hardware portability rather than an oversight, enabling efficient compilation across diverse word sizes and byte representations.
read it The piece provides a thorough historical breakdown of 1970s computer architectures and practical C patterns from Lua that justify the language's original type design.
summary
C's variable-width integer types allowed the language to run efficiently on historical hardware ranging from 12-bit to 60-bit word sizes, non-8-bit bytes, and non-two's-complement arithmetic. Forcing fixed widths would have crippled performance on the varied systems where C was born and initially ported. The post uses examples from the Lua source code to demonstrate how portable C can handle varying byte sizes correctly without assuming modern hardware traits. While modern systems have largely converged on standardized traits, this flexibility was essential for C's initial survival and widespread adoption.
key points
- Early computing architectures featured drastically different hardware models, including 12-to-60-bit word sizes, 6-to-9-bit characters, and ones'-complement arithmetic.
- Requiring fixed 32-bit integers would have doubled instruction overhead and execution time on 16-bit systems like the PDP-11 where C was developed.
- The Lua source code demonstrates how to write strictly portable C89 that adapts to platform-specific integer ranges and byte widths using macros like CHAR_BIT.
who should read it
Systems programmers and developers interested in computer history, language design, and low-level portability.
discussion mixed
consensus
Most commenters agree that flexible integer sizes were historically necessary given the chaotic hardware landscape of the 1970s, but many argue they have turned into an obsolete and error-prone liability today.
pushback
A minority notes that even today, niche hardware like digital signal processors lack 8-bit bytes, meaning C's hardware-agnostic types still serve a functional purpose outside mainstream desktop and server environments.
Where the flexible integer sizes break the most is when dealing with ABIs, which weren't really a concern before dynamic linking existed but are very much a concern today. We've also, for some reason, decided that the standard way of defining a library ABI is with a C header. That means that everyone has to worry about precisely defining integer sizes, as well as more esoteric types like size_t or intmax_t. Good writeup on all that here: https://thephd.dev/to-save-c-we-must-save-abi-fixing-c-funct...
It highlights how variable integer sizes introduce significant modern friction when defining stable binary interfaces across libraries.
Generated by an LLM from the article and thread. Check the sources before relying on it.