HACKER Q&A
📣 nateb2022

Is there a C standard library similar in style and function to Go's?


Out of all the languages I've used so far, I've come to appreciate Go's standard library the most. It's well structured and offers a very sensible scope of capabilities on a cross-platform basis. As far as I'm aware, C doesn't have any comparable standard library. I believe a Go-like standard library would make C a much more attractive language, especially if it includes a sensible coroutines implementation.

The ability to use a single standard library for UTF-8 strings, to parse JSON, compress/decompress gzip streams, and to serve a basic HTTP server, for instance, would be golden. And if, for instance, a standard library were to unite around common, analogous structures to Go's io.Reader/io.Writer, contexts, etc. there is much that could be gained at comparatively little cost.


  👤 shortrounddev2 Accepted Answer ✓
No. There are a million little implementations which try to do that, but one problem is the lack of generics. Any stack, linked list, hashmap, etc. implementation that tries to be sufficiently generic will need to either:

* Store all of its data as a void*, which is bad practice

* Implement the data structure for all primitive types, which wouldn't exactly help you if you wanted to start using them on custom structs

So you can find plenty of libraries implementing common data structures and algorithms, but they'll all require some kind of integration with your code

C++ has a much more robust container library (STL - Standard Template Library), with things like std::map, std::vector, std::string, std::stack, std::queue, and a variety of algorithms and functions in the header. Before C++ added all these neat features, there was boost, which implemented its own version of these things.


👤 fulafel
Most C implementations are hosted and like to keep compatibility with the C standard. So they go with the standard C stdlib.