3 ms·
I am confused. Having gone over quite a bit of the authors C code on GitHub, it seems he uses libC quite often. I read/follow his blog posts; most are well writ
by jdefr89 4y ago
I am confused. Having gone over quite a bit of the authors C code on GitHub, it seems he uses libC quite often. I read/follow his blog posts; most are well written and insightful. His code is rather elegant as well, making his code bases good for studying (I recommend them to mentees)… What am I missing here. I think libc is quite alright given its time in operation, I bet libC is the most widely used standard library on the planet by a large margin. If not libC then what? Musl, glib? Those are great as well but I think avoiding libC is somewhat silly..
- flohofwoe 4y agoYou use your own or someone else's non-standard wrapper libraries for specific OS services. For instance if you want to do asynchronous IO, or use virtual memory features, the C standard library is entirely useless anyway, so you create your own thin cross-platform wrappers over OS specific system API calls, or even call those OS specific functions directly (e.g. POSIX functions on UNIX-flavoured operating systems or Win32 functions on Windows). The C stdlib is essentially an SDK for very simple 70's UNIX-style command line tools, but operating systems have moved on, while the C standard library is unfortunately stuck in the past. (IMHO a "C stdlib v2" would be much more important than any new language features, but it doesn't look like the C committee wants to go down that road).
- woodruffw 4y agoThe post doesn't say he doesn't use libc; it says that he tries to minimize his use of it. It's very difficult to entirely avoid libc. musl and glibc are implementations of libc, not alternatives to it.
- eqvinox 4y agoglib != glibc; glib is Gtk/GNOME's OS-independent wrapping layer and in fact an alternative to using libc functions directly. E.g. here is glib's take on strcmp() as entry point: https://docs.gtk.org/glib/func.strcmp0.html https://docs.gtk.org/glib/func.strcmp0.html
- woodruffw 4y agoI know that; I assumed from context ("Musl, glib") that the GP has probably just dropped the "c" by accident, since musl is a libc implementation.
- mgaunard 4y agohow is it difficult to avoid libc? All you need are the system calls of your kernel. You don't need libc to call those.
- woodruffw 4y agoRelatively little of libc overlaps with the system call space: there's some I/O and a little bit of stuff that could be done with a system call (like time), but traditionally aren't for both concern separation and performance reasons. As a small example: `strtok` is simultaneously a very useful function and one that's annoying to use correctly (much less independently implement correctly). It isn't a system call.
- mgaunard 4y agostrtok is a trivial and not particularly good function, in part due to its poor API. You can write a better one in minutes (which is incidentally less than the time to understand the corner cases of this function's behaviour)