|
|
|
|
|
by sirwhinesalot
812 days ago
|
|
> If it were obvious it would have been done already. Witness the many variants that try to make it better but don't. Every other language with mutable strings, including C++, does it like that. It is obvious. The reason it is not done in C is not ignorance, it is laziness. > Which you then can't pass to any other library. String management is very easy to solve within the boundaries of your own code. But you'll need to interact with existing code as well. Ignoring the also obvious solution of just keeping a null terminator around (see: C++ std::string), you should only worry about it at the boundary with the other library. Same as converting from utf-8 to utf-16 to talk to the Windows API for example. |
|
Of course not. C has been around since the dawn of UNIX and the majority of important libraries at the OS level are written in it.
Compatibility with such a vast amount of code is a lot more important than anything else.
If it were so easy why do you think nobody has done it?
> Ignoring the also obvious solution of just keeping a null terminator around
That's not very useful for the general case. If your code relies on the extra metadata (length, size) being correct and you're passing that null-terminated buffer around to libraries outside your code, it won't be correct since nothing else is aware of it.