4 ms·
One drawback of these functions is that the return value is the length of the source string. This is seldomly useful, as it's mostly a micro-optimization to avo
by Denvercoder9 3y ago
One drawback of these functions is that the return value is the length of the source string. This is seldomly useful, as it's mostly a micro-optimization to avoid an extra string scan when using static buffers for small strings, but dynamic buffers for large ones. However, it prevents these functions from being used with input that might not be null-terminated, and causes performance to be bounded by the size of the source (which usually isn't controlled by the caller), instead of the destination (which usually is).
- ben_bai 3y ago> it prevents these functions from being used with input that might not be null-terminated Those are not valid C-strings! String functions are(have) "undefined behavior" for non string inputs!
- Denvercoder9 3y agoThat's true, but in practice you sometimes encounter such strings and it's nice if you can use the regular string functions with them, instead of having to special-code something.