4 ms·
Slightly related tangent: I'm looking for standards / set of libraries / best practices for "modern" C development, but I've yet to find a comprehensive resour
by makmanalp 13y ago
Slightly related tangent:
I'm looking for standards / set of libraries / best practices for "modern" C development, but I've yet to find a comprehensive resource.
Stuff like typedefing a manual fixed sized int type to be cross-platform compatible, that books don't really tell you to do but are important and come up often.
I'd be okay with a small, well written example library too. Does anyone happen to know something like this?
edit: Ah, sorry if I misled you, that was just an example of the kind of tips and pointers I was looking for. Or weird bits like the linux kernel list_head. http://kernelnewbies.org/FAQ/LinkedLists http://kernelnewbies.org/FAQ/LinkedLists Or common libraries like bstring that make life easy. Or even a single, comprehensive implementation of good data structures, since everyone seems to have their own vector.h and/or hash.h that fails to cover much other than their own use case.
- ldite 13y agoStuff like typedefing a manual fixed sized int type to be cross-platform compatible If you're lucky enough to be able to rely on C99: https://en.wikipedia.org/wiki/Stdint.h#Fixed-width_integer_types https://en.wikipedia.org/wiki/Stdint.h#Fixed-width_integer_t...
- kqr2 13y agoI like to recommend C Interfaces & Implementations http://www.amazon.com/Interfaces-Implementations-Techniques-Creating-Reusable/dp/0201498413/ http://www.amazon.com/Interfaces-Implementations-Techniques-... It uses Donald Knuth's literate programming which takes getting used to, however, it's a great case study of how to make a good library. There is a new book on "21st Century C" which I haven't read. It has mixed reviews, however. http://www.amazon.com/21st-Century-Tips-New-School/dp/1449327141/ http://www.amazon.com/21st-Century-Tips-New-School/dp/144932...
- deleted 13y ago[deleted]
- VMG 13y agoAs somebody with the same query, let me hop on - how does "Learn C the hard way" fare? I've got it mentally bookmarked the for next time I touch C code.
- falcolas 13y agoPretty good, in my opinion. It's fairly comprehensive, and focuses a lot of time and effort into pointing out why things in C break and how to be preemptive about fixing them. A fair bit of discussion around your standard exploits as well.
- JoachimSchipper 13y agoI'm a fan of BSD sys/queue.h and especially sys/tree.h; they are liberally-licensed header-only implementations of various kinds of linked lists resp. binary trees.
- mtdewcmu 13y agoYou may want to study the source code of a well-written, modern C project like git: https://github.com/git/git https://github.com/git/git The fixed-size int finally got a permanent solution: #include <stdint.h> If you are targeting autoconf/automake as your build system, that has a lot of built-in solutions to portability issues, like defining macros. It's not easy to learn, and I don't pretend to know it well, but when I'm compiling someone else's project, I'm always happy to see a configure script. The gtk project's libglib is a pretty comprehensive library of C data structures. The Apache Portable Runtime serves a similar purpose: http://en.wikipedia.org/wiki/Apache_Portable_Runtime http://en.wikipedia.org/wiki/Apache_Portable_Runtime What I find annoying about libraries like glib is that they tend to impose their own style on your project by using their own typedef'ed types and such. If you don't mind it, you can cobble together your own data structures from various open-source projects. Judy arrays are pretty fast, and you can use them in a variety of ways. Searching google for "c hash table" came up with a lot of excellent results, so try googling whatever data structure or algorithm you need, and chances are, you'll find something.
- bjourne 13y agoGlib/GObject is pretty good and seems to be what you're looking for: https://developer.gnome.org/glib/2.37/ https://developer.gnome.org/glib/2.37/ It's not tied to the GNOME platform at all but rather contains building blocks such as hash maps, linked and array lists, heap allocators, string manipulation functions and so on. Personally, I find some parts of GObject to be over engineered and distasteful but most of it is solid utility. Then you have https://wiki.gnome.org/Vala https://wiki.gnome.org/Vala which is a whole new language built on top of C + Glib/Object whose main selling point is that it compiles to, and is totally compatible with, plain C code. Do keep in mind that all of this, Glib, Vala, Cello and other "make C more like a high-level language" are basically hacks to workaround the fact that C is a very low-level language and lacks many powerful features. I believe one is much more productive using Glib + C than just plain C, but you are still less productive than if you had choosen a modern language in the first place.