3 ms·
You shouldn't use any of those garbage functions. Just ignore \0 entirely, manage your lengths, and use memcpy.
by sirwhinesalot 1y ago
You shouldn't use any of those garbage functions. Just ignore \0 entirely, manage your lengths, and use memcpy.
- masternight 1y agoYeah, Drepper said the same thing.
- hkpack 1y agoI am not writing in C, but always wondered, why pascal-like strings wrappers are not popular, i. e. when you have first 2 bytes represent the length of the string following by \0 terminated string for compatibility.
- sirwhinesalot 1y ago2 bytes is not enough, usually you'll see whole "size_t" worth of bytes for the length. But you could do something utf-8 inspired I suppose where some bit pattern in the first byte of the length tells you how many bytes are actually used for the length.
- renewedrebecca 1y agoPascal originally required you to specify the length of the string before you did anything with it. This is a totally good idea, but was considered to be too much of a pain to use at the time.
- hnfong 1y agoIn C you have to do that too, like... malloc()?
- int_19h 1y agoYou still need a 0-terminated string to pass to API of most libraries (including ones included with the OS - in this case, Win32).