C language > Work in progress

Containers for C code review

(1/1)

AB:
Hello, I started a project to mimic the containers from the C++ Standard Library in the C language. The implementation is 100% macro, and I want to find and fix bugs and coding mistakes early on, hence this post.

The project files are for Pelles C 8.0 with GNU makefiles for Linux users. The chosen language standard is C99 and the "license" is Creative Commons Zero (CC0) public domain.

Code example for ctnr/string.h:


--- Code: ---#include <stdio.h>
#include "ctnr/string.h"

int main(void)
{
    string s;

    if (string_create(s, "Hello"))
    {
        string_strcat(s, " World!");
        printf("\"%s\" (length %zu)\n", string_cstr(s), string_len(s));
        string_destroy(s);
    }
}

--- End code ---

Code example for ctnr/dynarray.h:


--- Code: ---#include <stdio.h>
#include "ctnr/dynarray.h"

int main(void)
{
    dynarray(int) dai;

    if (dynarray_create(dai, 3))
    {
        dynarray_ptrcopy(dai, ((const int []){10, 20, 30, 40}), 4);
        printf("Size: %zu, Capacity: %zu\n",
            dynarray_size(dai), dynarray_capacity(dai));
        printf("Contents: ");

        for (dynarrayiter(dai) it = dynarrayiter_begin(dai);
            it != dynarrayiter_end(dai);
            dynarrayiter_inc(it))
        {
            printf("%d ", dynarrayiter_deref(it));
        }

        printf("\nElement at index 2: %d\n", dynarray_at(dai, 2));
        dynarray_destroy(dai);
    }
}

--- End code ---

Website: https://sourceforge.net/projects/ctnr/
Code: https://sourceforge.net/p/ctnr/code/HEAD/tree/

For your convenience, the snapshot of Revision 1 was attached to this post.

frankie:
Good Job!  :)
Thanks.

cnoob:
Is this project dead? It's interesting to me  :-[

Navigation

[0] Message Index

Go to full version