Lesser-Known but C Language Facts That Might Surprise You
1. Undefined Behavior for Performance: C deliberately includes undefined behavior (UB) for things like signed integer overflow or dereferencing null pointers. This isn’t a bug—it’s a design choice. By leaving behavior undefined, compilers can make radical optimizations. For example, they can assume a signed integer never overflows and remove “dead” code handling that case, improving performance.
2. Variable Declarations Mimic Usage: Dennis Ritchie admitted that C’s declaration syntax (e.g., int *p) can be confusing because it mirrors the variable’s use. While controversial, he insisted there’s a certain logic behind it, tying declaration to how the variable is used.
3. Trigraphs and Digraphs: C once supported “trigraphs” (three-character sequences like ??= for #) and “digraphs” (two-character sequences like <: for [) to help with portability on old systems lacking certain symbols. Trigraphs were officially removed in C23.
4. The Struct Hack & Flexible Array Members: C programmers long used the “struct hack” to create variable-length structs by adding a zero-length array at the end of a struct. C99 formalized this with flexible array members, making variable-length structs officially supported.
Even decades later, C still hides these little gems that reveal both its history and its genius.
No comments yet