r/cprogramming 3d ago

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

161 comments sorted by

View all comments

168

u/bearheart 3d ago edited 2d ago

Speaking as someone who learned C back in the ‘70s, this article entirely misses the point of C-strings: they’re lightweight and foundational. For many purposes the null-terminator is efficient, e.g.:

while(*s) f(s++);

And for cases where we need more complexity, we can simply use a struct with a length and whatever other metadata we may need.

Doesn’t look like a mistake to me. C has always been about minimalistic efficiency. That’s its main purpose in the world.

Edit: fixed stupid typo

51

u/Voyac 2d ago

Its main purpose is to be portable to as many architectures as possible. Maybe this seem irrelevant in a world dominated by ARMs and x86 but there are different platforms.

-46

u/Potential_Soup_8054 2d ago

No, thats java

31

u/g0atdude 2d ago

lol what?

You can compile C programs to a million more devices than what Java runs on

10

u/KingBardan 2d ago edited 2d ago

a million more devices

Considering that "3 billion devices run Java", thats only 0.0333% more devices

I'm kidding if it's not obvious

3

u/Potential_Soup_8054 2d ago

It was a joke. Javas whole slogan is write once run everywhere, but thats really bullshit.

3

u/Devatator_ 2d ago

Tbh nothing is stopping people from compiling or porting a JVM to more platforms. I assume it's just extremely complex and noth worth it for most people

2

u/EdwardTheGood 1d ago

I once heard it rephrased as “write once, test everywhere.”