3 ms·
I think he's also not giving enough emphasis to the technical realities of the time. When K&R was written, bytes were EXPENSIVE, tracking the size of a string
by georgemcbay 14y ago
I think he's also not giving enough emphasis to the technical realities of the time. When K&R was written, bytes were EXPENSIVE, tracking the size of a string that had to be longer than 255 characters using anything but end-termination would result in every string wasting precious bytes.
Everyone agrees that NULL-terminated C strings are the wrong thing to do now, this is why virtually every modern language (including Go, which is obviously very C-inspired) splits a string into data and length as separate entities (even if this separation is mostly hidden from the language user).
But when you only have a handful of thousands of bytes for an entire system, you just have to accept some amount of unsafeness as a practical reality. Should K&R be amended with a warning lest it mislead people working on modern systems? Maybe. But I don't think it is fair to code review it using modern thinking about the expense of different operations and the modern luxury of vast amounts of memory.