NO

Author Topic: Containers for C code review  (Read 5158 times)

AB

  • Guest
Containers for C code review
« on: October 15, 2016, 05:24:52 PM »
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: [Select]
#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);
    }
}

Code example for ctnr/dynarray.h:

Code: [Select]
#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);
    }
}

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.
« Last Edit: October 15, 2016, 05:29:56 PM by AB »

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2096
Re: Containers for C code review
« Reply #1 on: October 15, 2016, 08:23:13 PM »
Good Job!  :)
Thanks.
It is better to be hated for what you are than to be loved for what you are not. - Andre Gide

cnoob

  • Guest
Re: Containers for C code review
« Reply #2 on: September 06, 2018, 12:51:46 PM »
Is this project dead? It's interesting to me  :-[