Did Ken, Ritchie and Brian choose wrong with NUL-terminated text strings? (2011)
Report a link problem
Submission timeline
2007–2026One slot for every year since HN launched. Height is that year's peak points; orange marks a 100+ point or 50+ comment breakout. Select a bar to open its strongest thread.
First comments on top threads
HN comment orderIn the article he says it is just one byte extra, but that's clearly not the case, since we probably want strings longer than 255 characters. To be practical, even in the sort term, you'd probably need at least two bytes, and that's still a bit limiting. NUL-terminated strings keep you from having to worry about the size of the length specifier and what byte ordering when storing it. He notes that other languages of the day didn't go with…
Worth keeping in mind that the security cost here is illusory: the track record of length-delimited data structures isn't much better than that of ASCIIZ, especially since integer handling in C is so treacherous.
Very good article. There is a huge cultural blindfold that Unix/C have formed indirectly formed on everybody's thinking about computers. Most of us have never used computers outside the Unix sphere of influence. The point about hardware (in this case instruction set) adapting to Unix/C strings is also a recurring pattern, and makes it hader to climb out of the pit of local optimum /path dependence. Fun thought experiment to think how things might have turned out if ideas from…
Null terminated strings always seemed to me like a terrible idea, but on the other hand, 255-character maximums aren't really reasonable. What we need are strings prefixed with a length of the length of the string and then the length as a variable length integer.
The first top-level comment from each of the four biggest threads, in HN’s own order. Excerpts are shortened; open a comment for full context.
- Breakout years
- 2
- Total points
- 280
- Total comments
- 165
100+ points or 50+ comments
reference only — not used in Hall rules or ranking
reference only — not used in Hall rules or ranking
Every submission
| Date | Title as submitted | By | Points | Comments |
|---|---|---|---|---|
| 2011-08-02 | The Most Expensive One-byte MistakeFirst breakout · Best thread | CowboyRobot | 146 | 79 |
| 2012-04-26 | Poul-Henning Kamp: The Most Expensive One-byte Mistake | cpeterso | 52 | 15 |
| 2014-09-29 | The Most Expensive One-byte Mistake (2011) | eric59 | 8 | 8 |
| 2016-11-01 | The Most Expensive One-Byte Mistake | seycombi | 1 | 0 |
| 2018-01-16 | Did Ken, Ritchie and Brian choose wrong with NUL-terminated text strings? (2011)Latest 20+ point return | mayankkaizen | 55 | 55 |
| 2019-10-21 | The Most Expensive One-Byte Mistake (2011) | c89X | 2 | 1 |
| 2019-12-04 | The Most Expensive One-Byte Mistake: Was Nul-Terminated Text Strings Wrong? | pcr910303 | 12 | 7 |
| 2021-06-11 | The Most Expensive One-Byte Mistake | pelayjesus | 2 | 0 |
| 2024-01-17 | The Most Expensive One-Byte Mistake (2011) | xanderlewis | 2 | 0 |