Introduction

libcpr is a public domain backport of the core data structures and algorithms from the C++11 standard library to C.

Features

  • Implements a straightforward mapping from C++ to C, with consistent naming.
  • No runtime dependencies other than C99 and the system’s C++ standard library.
  • No build prerequisites beyond the Autotools toolchain and a C++11 compiler.
  • Compatible with Clang and GCC, or indeed any standard C++11 implementation.
  • Plays nice with others: all exported symbols are prefixed with cpr_.
  • 100% free and unencumbered public domain software, usable in any context and for any purpose.

Motivation

The C standard library is severely deficient in useful data structures essential to modern programming practice. Consequently, most non-trivial C programs and shared libraries include one-off implementations of even the most elementary data structures such as dynamic arrays and hash tables. This harms programmer productivity, bloats the sizes of binaries, wastes machine resources, and inevitably introduces unnecessary bugs–including security vulnerabilities.

The alternative to rolling your own data structures has thus far been to pull in a large, all-purpose library dependency such as GLib. The problem with this approach is that you just wanted a hash table, but you got the kitchen sink with an XML parser thrown in for good measure. These all-purpose libraries have a huge footprint and can be difficult to install, ensuring that your potential user base will prefer competing projects who do roll their own data structures.

libcpr is a new take on an old problem. Given that every modern desktop and server system today is guaranteed to already have not merely the C standard library but also the C++ standard library, libcpr provides the until-now missing glue to access that latter library from pure C. The C++ standard library contains the basic data structures and algorithms needed for most common programming tasks, and adds no bloat since it’s already installed on the system regardless.

Current Status

At present, vectors and strings are partially implemented. Other sequence containers (list, deque) and associative containers (set, multiset, map, multimap) are planned but not yet implemented.