A C11
library providing generic type-safe data structures compiling to actual
structures and functions.
- Quick overview
- Getting Started
- Documentation
- Versioning
- Changelog
- Contributing
- Interesting links
- License
- Thanks
#include <ctl/ctl.h>
#include <ctl/ctl_dyn_array.h>
#define CTL_DYN_ARRAY_TYPES_TYPES int, char
CTL_DECLARE(CTL_DYN_ARRAY, CTL_DYN_ARRAY_TYPES);
CTL_DEFINE(CTL_DYN_ARRAY, CTL_DYN_ARRAY_TYPES);
int main(int argc, char * argv[])
{
CTL_DYN_ARRAY(int) * foo = ctl_DynArray_Create(foo);
CTL_DYN_ARRAY(char) * bar = ctl_DynArray_Create(bar);
ctl_DynArray_PushBack(foo, 3);
ctl_DynArray_PushBack(foo, 7);
ctl_DynArray_PushBack(bar, 'b');
int a = ctl_DynArray_PopBack(foo); // a = 7
char b = ctl_DynArray_PopBack(bar); // b = 'b'
ctl_DynArray_Destroy(foo);
ctl_DynArray_Destroy(bar);
return 0;
}
Although ctl
is a header only library, a C11
compliant compiler is needed to
use it in your project and to compile the tests.
Download or clone the repository:
git clone https://gitlab.com/callback/ctl.git
Optionally run the tests:
cd ctl
make all
make check
Install the headers globally to the standard default location /usr/local/include/ctl
:
make install
Or install them to a different path /my/custom/path/include/ctl
:
make install prefix=/my/custom/path
Add /usr/local/include/ctl
or /my/custom/path/include/ctl
to your include
paths.
Doxygen documentation is available here: https://callback.gitlab.io/ctl
This project follows Semantic Versioning.
See the CHANGELOG.md file.
See the CONTRIBUTING.md file.
Here are a few interesting generic data structures libraries in C.
- stb_ds.h: This is a single-header-file library that provides easy-to-use
dynamic arrays and hash tables for C (also works in C++).
- Part of the well known stb library by Sean Barrett.
- Klib: A standalone and lightweight C library.
- Collections-C: A library of generic data structures including a list, array, hashtable, deque etc...
This project is licensed under the very permissive BSD Zero Clause License.
More information on the 0BSD license: