3 ms·
what should be the replacement for C stdlib?
by mi_lk 3y ago
what should be the replacement for C stdlib?
- hgs3 3y agoThe stdlib is mostly fine. The string and character classification functions are outdated because they aren't Unicode aware. There's a more detailed write up here [1]. [1] https://nullprogram.com/blog/2023/02/11/ https://nullprogram.com/blog/2023/02/11/
- flohofwoe 3y agoIt's not just the missing UNICODE support (although that's probably out of scope for the stdlib, a couple of UTF-8 aware helper functions would be good enough), but footguns-in-waiting like strcpy(), strncpy(), strcat(), strncat(), ... All the wide string stuff (wchar.h and wctype.h) as well as locale.h is all pointless today. Everything related to filesystems and file IO is just the bare minimum that's acceptable for simple UNIX-style command line tools, but not really useful in modern applications (most notably, any support for non-blocking IO and memory-mapped-files are missing). Arguably, complex.h doesn't even belong in the stdlib (I wonder why such an esoteric feature was even considered). Better support for custom allocation strategies would be nice (e.g. each function which allocates under the hood should accept an allocator argument instead of being hardwired to malloc). I'm not even asking for a more feature-rich stdlib, a stdlib2 with the obsolete parts removed and modernized IO and memory management functions would go pretty far. But then of course there's the problem that the C stdlib is also accidentially the de-facto system API on some UNIXes.
- mattpallissard 3y ago> any support for non-blocking IO and memory-mapped-files are missing Sure but POSIX supports that and it may as well be the stdlib for those of us in *nix land.
- flohofwoe 3y agoThere isn't a proper universal solution unfortunately apart from looking for 3rd-party-libs which provide better abstractions over the underlying OS APIs (or writing those yourself).
- musicale 3y agoA new standard C library without unbounded pointers would be a major improvement. Including a more complete set of common operations (particularly string and vector operations) would be helpful as well. etc.