Hacker News new | ask | show | jobs
by MrBingley 2937 days ago
Looking at the comments in this post, I'm resigning myself that there simply is no correct solution for copying or concating strings in C. Null-terminated strings are a fundamentally broken concept. I think the long-term solution is simply to move to a different language (Rust, C++, D, Go, whatever) where we have the benefit of hindsight and have (pointer, length) string types, which solve all the problems null-terminated strings introduce.
2 comments

It's quite sad to behold how hard it is to work with strings in C.

All those functions seem broken by design, forcing the programmer to clean up their mess in edge cases.

You could also validate on interface transition and use your own type internally; which is often what happens when using another language and exporting C style library bindings.