Re:Git's list of banned C functions
by kelnos on Thursday March 04, 2021 @09:32PM
(#26351784)
Because most projects involve interfacing with other third-party libraries that will undoubtedly not know about this other third-party library that implements a nice string.
[ Parent
| on HN ]
It can contain a to_cstring() function and problem solved.
If it uses a struct with length of string and pointer to a c-style string, even the conversion can be elided (at the price of some inflexibility/unnecessary copying while in use)
That would mean you lose the ability to do all sorts of optimizations and memory sharing. Or at least, you can do them, but then the c_string() function requires copying the data. And that also means that it's a one-way thing: you can't use the copy on something that wants to modify the string, and expect your FancyString instance to reflect the modification.