4 ms·
The author rambled about the annoyances of string.h functions. And I do not disagree with many of the points made. Particularly strtoks global state and wholly
by anthomtb 4y ago
The author rambled about the annoyances of string.h functions. And I do not disagree with many of the points made. Particularly strtoks global state and wholly unintuitive usage.
But what is the alternative? Rolling your own equivalents?
- pavlov 4y agoMy approach is to use OS-specific C libraries like Apple’s CoreFoundation wherever possible. CFString is greatly superior to bad old C strings. If you need cross-platform, depending on your application it may be reasonable to create wrappers for your string usage with platform-specific implementations that use the best option available on each OS and fall back to POSIX.
- kevin_thibedeau 4y agoStrtok_r() is usually available as is the case for the other lib functions with global state. If not, it is a simple function to clone with whatever improvements you wish. I have a version that doesn't insert NULs so it can be used on read-only strings.
- Gibbon1 4y agoReminds me I need to rework mine to use slices.
- mqus 4y agoparticularly strtok is easy to replace imho. Ans if you've done so before, you can just accumulate and use your own "libc". Maybe not an entirely reusable one but enough of it. I can entirely imagine "rolling your own", as libc is not that big. But then again, I'm not a C dev by trade.