Why C Char Is at Least 8 Bits Not Exactly 8
The C programming language defines char as having at
least 8 bits rather than an exact size of 8 bits primarily to ensure
hardware portability and efficiency across diverse computer
architectures. When the C standard was established, hardware designs
varied significantly, and many processors could not natively address
8-bit chunks of memory. By defining char as the smallest
addressable unit of memory that contains at least 8 bits, the C standard
allows compilers to map native memory addressing directly to language
types without incurring heavy performance penalties from software
emulation.
Historical Hardware Diversity
When C was created at Bell Labs in the early 1970s and later
standardized by ANSI in 1989 (ANSI C / C89), the 8-bit byte (an octet)
was not the universal standard it is today. Mainframes and minicomputers
operated with word sizes such as 18, 24, 36, or 60 bits. For example,
systems like the PDP-10 used 36-bit words, frequently divided into five
7-bit characters or four 9-bit characters. If the C standard had
mandated an exact 8-bit char, running C on these
architectures would have been impractical or inefficient.
The Role of
char as the Minimum Addressable Unit
In C, sizeof(char) is explicitly defined to be
1 by definition. The type char does not merely
represent a text character; it represents the fundamental allocation
unit of memory.
A pointer to char (char*) is designed to
address individual units of storage in memory. If a machine's
architecture only allows memory to be addressed in 16-bit or 32-bit
words, forcing an exact 8-bit char would mean a standard
pointer could not directly access memory. The compiler would have to
generate complex shift-and-mask assembly instructions for every single
memory read and write, substantially degrading performance.
Relevance to Embedded Systems and DSPs
While 8-bit multiples dominate general-purpose computing today,
architectures with non-8-bit addressable units remain common in embedded
computing. Many Digital Signal Processors (DSPs), such as the Texas
Instruments TMS320C55x series or Analog Devices SHARC processors, have
smallest addressable units of 16 or 32 bits. On these systems,
CHAR_BIT (defined in <limits.h>) is set
to 16 or 32. This allows standard C code to compile into direct,
high-speed native memory instructions.
Fixed-Width Integers for Strict Sizing
For applications requiring exact byte counts—such as network
protocols, hardware drivers, or binary file formats—the C99 standard
introduced fixed-width integer types in <stdint.h>.
Types like uint8_t and int8_t guarantee
exactly 8 bits with two's complement representation. However, these
types are deliberately marked as optional in the standard: if an
underlying architecture cannot natively or efficiently support an exact
8-bit integer, it simply does not define uint8_t, leaving
char to operate at the native minimum width.