Looking for a source of middle sized code chunks
Asked Answered
M

5

12

The longer I'm working as a C developer I find myself lacking some source of middle sized code chunks.

I have source of code snippets and libraries, but I can't find a good source for code sized in between. Something that is a header, or a header+implementation file but isn't a library but is included into the project.

Stuff like a dynamic array, or linked list or some debugging or logging helpers.

I know that its partially due to C developers DIY mentality, but I just don't believe that people don't share stuff like this.

Manipular answered 24/3, 2011 at 0:20 Comment(2)
And when you've worked even longer and written all your own you'll forget to share them too ;) (well, you probably won't be able to because they were written on company time...)Masaccio
If you do have your own snippets and do want to share them, I still think git with submodules is a great way to do so. I started my own tidbits library with individual snippets as submodules that everyone can pull into their project. I don't currently have time to keep working on it, but I will do in the future, as having good reusable snippets at hand is a lifetime investment anyway. See this question: #4099874Ledezma
C
8

You might want to check out http://nothings.org for some single file (moderately sized) projects that include (image) decompression, font rasterization and other useful things.

Cracy answered 4/5, 2011 at 11:12 Comment(1)
This is the answer I would have given if I remembered the link. +1Florey
G
4

You may also want to look at CCAN.

Gidgetgie answered 10/5, 2011 at 19:37 Comment(0)
P
3

http://www.koders.com/ is worth checking. You might find something usefull now and then.

You can also sort the results by license which is pretty handy feature.

Pell answered 26/3, 2011 at 7:38 Comment(0)
P
0

There's a handful of utility libraries that spring to mind quickly; glib provides a wide variety of useful little utilities, including:

doubly- and singly-linked lists, hash tables, dynamic strings and string utilities, such as a lexical scanner, string chunks (groups of strings), dynamic arrays, balanced binary trees, N-ary trees

(And yes, glib is useful even in non-graphical environments; don't let its GNOME-background fool you. :)

The Apache portable runtime is a library that helps abstract away platform-specific knowledge; I've seen a handful of programs use it. It feels like enough programmers are content with "It runs on Linux" to not really worry about platform differences, and forgo learning Yet Another Library as a result. It feels more like a systems-level toolkit:

Memory allocation and memory pool functionality, Atomic operations, Dynamic library handling, File I/O, Command argument parsing, Locking, Hash tables and arrays, Mmap functionality, Network sockets and protocols, Thread, process and mutex functionality, Shared memory functionality, Time routines, User and group ID services

Puffball answered 24/3, 2011 at 0:29 Comment(9)
The problem is that in most cases I simply can't drag these libraries with the project. I can add stuff to the build system, but external dependencies generally tend to be a huge issue.Marcoux
@Let_Me_Be, many (most?) non-trivial projects rely on external dependencies; you can use tools like Debian's buildd or openSUSE Build Service to make sure your requirements are documented when building and distributing packages.Puffball
@Puffball There are several problems actually. I work on projects that tend to be deployed on enterpriser distributions (sane versions of libraries are big issue here) plus these project already have a looong history, so adding new dependencies is a big political issue.Marcoux
@Let_Me_Be, ah, Been There Done That. It's so much easier to write good software than enterprise software.Puffball
@Let_Me_Be This can be somewhat mitigated by keeping a copy of a dependency in your source tree, and statically linking.Lenoir
I would not call these examples "middle sized" but rather "gigantically bloated"...Stiegler
@R.., libglib is 901k, libapr is 222k on my system. 17 processes on my system use libglib and share its mapped image. My memory pressure might go up if each of those programs had re-written their tools from scratch. (And this gives one nice place to fix bugs, too. :)Puffball
I was more referring to whether these libraries satisfy OP's request than their merits, but I think you're mistaken about memory pressure. Using a library that brings heavy OOP idioms to C, with lots of small allocations, is surely going to increase memory pressure on the heap, compared to writing the equivalent code with C idioms. The code size issue is largely tangential.Stiegler
By the way, for an idea of what I mean, see here: domino.watson.ibm.com/comm/research_people.nsf/pages/…Stiegler
H
0

I always look at the Python (C) source code first when I am looking for the "best" way to code something up in C. Guido van Rossum's C coding style is concise and clear and given the number functions and features supported in the standard python libraries there is nearly always a useful/relevent snippet of code in there.

Harrelson answered 10/5, 2011 at 10:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.