Live data from Hacker News

SDS: Simple Dynamic Strings library for C

github.com

11–20 of 48 posts

Re: SDS: Simple Dynamic Strings library for C

#11
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

There are real downsides to even #including C++ headers. And there are certainly downsides to introducing a templated string type. It's not hard to imagine why people would want another solution.

Re: SDS: Simple Dynamic Strings library for C

#12
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

To actually answer your question (beyond the snark/appeal to authority replies you’ve already gotten), there are a couple good reasons: — You're working in embedded development (but somehow need a full-fledged dynamic string library). — While it's true that C++ is (almost) a strict superset of C, and “you don’t pay for what you don’t use” is a good rule of thumb, it can be very hard to restrict a team of developers t…

> You're working in embedded development (but somehow need a full-fledged dynamic string library).

The situation isn't all that implausible: e.g., many ESP32-based devices want to work with strings to interface with HTTP servers, and they do have C++ support, but the size limit is small enough that you can easily bump your head into it if you aren't careful.

Re: SDS: Simple Dynamic Strings library for C

#13

Earlier quoted context omitted.

To actually answer your question (beyond the snark/appeal to authority replies you’ve already gotten), there are a couple good reasons: — You're working in embedded development (but somehow need a full-fledged dynamic string library). — While it's true that C++ is (almost) a strict superset of C, and “you don’t pay for what you don’t use” is a good rule of thumb, it can be very hard to restrict a team of developers t…

> You're working in embedded development (but somehow need a full-fledged dynamic string library). The situation isn't all that implausible: e.g., many ESP32-based devices want to work with strings to interface with HTTP servers, and they do have C++ support, but the size limit is small enough that you can easily bump your head into it if you aren't careful.

Or anything processing JSON— it's nice to be able to get string views directly into the original payload without having to copy them into fixed size buffers elsewhere.

Re: SDS: Simple Dynamic Strings library for C

#14
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

I switched to C because I could not stand the pain of using C++ anymore. I find C refreshingly simple.

(Also, as a comment to other responses: C++ is not a superset of C, it is a fork from 95 with divergent language evolution since then).

Re: SDS: Simple Dynamic Strings library for C

#15
post #5
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

Suggesting C++ as a solution in the face of "masochist obsession" is... an interesting choice :-D

Totally. As a C developer, I really suffer whenever I need to touch anything C++.

Re: SDS: Simple Dynamic Strings library for C

#16
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

How am I supposed to use C++ strings and string_views in C?

Re: SDS: Simple Dynamic Strings library for C

#17
I'm surprised this is aliased to char*, not const char*. The benefit of the aliasing is convenience, but the main risk is absent-mindedly passing it to a libc function that modifies the string without updating the SDS metadata. Const would result in a compiler warning while letting the intended use cases (e.g., the printf example) work fine.

Re: SDS: Simple Dynamic Strings library for C

#18
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

Someone had to create C++ strings so C++ developers could use them. What's wrong with someone doing the same for C so C developers can use it?

Re: SDS: Simple Dynamic Strings library for C

#20
post #2

Why not just use C++ strings and string_views? So weird to see this masochistic obsession some people have with doing everything in plain C. It's 2026, there are better, more memory safe, more efficient solutions out there.

To actually answer your question (beyond the snark/appeal to authority replies you’ve already gotten), there are a couple good reasons: — You're working in embedded development (but somehow need a full-fledged dynamic string library). — While it's true that C++ is (almost) a strict superset of C, and “you don’t pay for what you don’t use” is a good rule of thumb, it can be very hard to restrict a team of developers t…

> and the STL

Even this has a lot of "payment" for what you don't use. Even some C++ libraries forbid it just because of the size of debug symbols.

Post reply on HN