3 ms·
All string manipulation code in C deals with trailing NULL bytes, so if you try doing something different, you may get issues when you try to link to other code
by keeperofdakeys 11y ago
All string manipulation code in C deals with trailing NULL bytes, so if you try doing something different, you may get issues when you try to link to other code. It's not a great system, but good C programmers should know the shortfalls.
As an example of the alternate approach, the Rust language uses (ptr, size) to represent all arrays (called slices) and strings internally. This seems like a much better method, allowing you to reference substrings without allocating a buffer, and perform out-of-bounds checking at runtime.