r/cprogramming • • Aug 17 '26

C Strings: A 50-Year Mistake

https://longtran2904.substack.com/p/c-strings-a-50-year-mistake?r=8qz2zb&utm_campaign=post&utm_medium=web
212 Upvotes

172 comments sorted by

View all comments

Show parent comment

1

u/Maleficent_Memory831 Aug 17 '26

The alternatives at the time were counted strings or fixed length fields. Both were annoying, inefficient, and had just as many problems as C strings or more. Ie, one byte for length doesn't cut it. Two bytes for length might not cut it, and definitely wastes space in the limited RAM at the time. Fixed field lengths are a nightmare early Fortrans, and some operating systems).

Then there's the stuff that pack multple characters into a single word (ie, Zork did this, 36-bit word on the PDP-10, you can stick in six 6-bit characters (maybe only 5 if they used upper bits for tag). Digital used 7-bit characters thus 5 characters and one leftover bit. 0 or all 1s as the final character signals the end.

0

u/Intelligent_Part101 Aug 18 '26

Two bytes for counted length would waste memory? That's only ONE BYTE MORE per string than a null terminated string uses.

2

u/alkatori Aug 18 '26

C gave you a byte and here you are arguing for a whole snack!

3

u/Intelligent_Part101 Aug 18 '26

Memory is like potato chips. You can never consume enough.