Type-safe generic data structures in C

This page summarizes the projects mentioned and recommended in the original post on news.ycombinator.com

Our great sponsors
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • WorkOS - The modern identity platform for B2B SaaS
  • SaaSHub - Software Alternatives and Reviews
  • freebsd

    FreeBSD's source with custom patches (by lattera)

  • The macro idea has a long history. It would be good to reference its earlier uses. For example, freebsd/netbsd had "tree.h" back in 2002 [1].

    [1] https://github.com/lattera/freebsd/blob/master/sys/sys/tree....

  • libcperciva

    BSD-licensed C99/POSIX library code shared between tarsnap, scrypt, kivaloo, spiped, and bsdiff.

  • InfluxDB

    Power Real-Time Data Analytics at Scale. Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.

    InfluxDB logo
  • ctl

    My variant of the C Template Library (by rurban)

  • I favor the CTL over the STL anytime, because it compiles much faster, is much smaller, no indirect vtable calls, no bloated god objects, has no magic hooks attached, like dereferencing refs and ops, is clear on stack vs heap allocation.

    The downside of course is that generics and iterators on those are a bit more troublesome, only compiler dependent goodies (mostly only clang, not gcc), like overloads or constexpr. C++ templates are ugly, and the STL is very buggy and limited. Also no security and no performance. They started on the wrong foot and had to keep it there.

    Rust has an annoying syntax, but a much better library culture.

    https://github.com/rurban/ctl

  • pottery

    Pottery - A container and algorithm template library in C (by ludocode)

  • Yes! The include style of templates in C is way better than the old way of huge macros to instantiate code. The template code can look mostly like idiomatic C, it interacts way better with a debugger, it gives better compiler errors... everything about it is better and it's finally starting to become more popular.

    I've open sourced my own C template library here:

    https://github.com/ludocode/pottery

    Not only does it use the #include style of templates, but it actually makes the templates composable. It takes this idea pretty far, for example having a lifecycle template that lets you define operations on your type like move, copy, destroy, etc. This way the containers can fully manage the lifecycles of your types even if they're not bitwise movable.

    There's also this other more popular C template library, one that tries to more directly port C++ templates to C but with a lot less features:

    https://github.com/glouw/ctl/

  • ctl

    The C Template Library

  • Yes! The include style of templates in C is way better than the old way of huge macros to instantiate code. The template code can look mostly like idiomatic C, it interacts way better with a debugger, it gives better compiler errors... everything about it is better and it's finally starting to become more popular.

    I've open sourced my own C template library here:

    https://github.com/ludocode/pottery

    Not only does it use the #include style of templates, but it actually makes the templates composable. It takes this idea pretty far, for example having a lifecycle template that lets you define operations on your type like move, copy, destroy, etc. This way the containers can fully manage the lifecycles of your types even if they're not bitwise movable.

    There's also this other more popular C template library, one that tries to more directly port C++ templates to C but with a lot less features:

    https://github.com/glouw/ctl/

  • Klib

    A standalone and lightweight C library

  • This is in fact a pretty common pattern in production code.

    Here's an entire suit of type safe generic data structures in C: https://github.com/attractivechaos/klib

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts