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
211 Upvotes

172 comments sorted by

View all comments

1

u/Key_River7180 Aug 17 '26

Has the model ever caused much trouble, though?

3

u/WittyStick Aug 17 '26

Yes.

Countless buffer overflow exploits due to poor string handling.

Not all, but many of these easily avoidable with sized strings.

1

u/Key_River7180 Aug 17 '26

I meant performance issues, like C strings are really efficient, for most purposes

1

u/SLiV9 Aug 17 '26

They're not; they are way less efficient than sized strings in almost all circumstances on a modern CPU.

Case in point, a lot of basic string operations on C-strings are made faster by adding a strlen() at the start.

1

u/deaddyfreddy Aug 18 '26

Computers became faster every year (and the process was dramatically faster in the 1980s), so even if fixed-size strings made things 10% less efficient (did they?), one could reasonably expect hardware improvements to compensate for that very soon. Alternatively, companies could save money on the man-hours spent fixing bugs caused by null-terminated strings and buy better hardware instead.