Skip to content

bjorndm/clad

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLAD

Introduction

CLAD is a pure and plain C Library with Algorithms and Data structures for general use under development. CLAD is written in ANSI 89 C, with as only extension that the public names are longer than 6 characters. CLAD is licensed under the MIT license.

By large the idea of this library is to provide a liberally MIT licensed library for ANSI C, filled to the brim with all sorts of useful macros, algorithms and data structures that are not present in the C standard library, but that are commonly found in other programming languages. Useful features from other MIT licensed libraries may be incorporated into this library as well.

CLAD already provides a first version of the following features:

  • useful preprocessor macros.

  • simple unit testing.

  • malloc wrappers (needed on some platforms).

  • allocators

  • platform detection macros based on Bjorn Reese’s work.

  • simple json parser based on Serge A. Zaitsev’s work

The following features are under development:

  • simple memory pools

  • simple string buffers

  • simple regular expressions

The following features are planned:

  • dynamic arrays

  • linked lists

  • intrusive linked lists

  • binary trees

  • intrusive binary trees

  • preferably hand-written documentation in Asciidoc format.

  • …​

Implemented Features

Name Space Emulation

Several modules of CLAD enable name space emulation though const structs filled with function pointers. Usage is very simple. If [module] is the clad module you want to use and [ns] is the name space pointer you want to import it as, then declare a name space like this:

#include "clad/module.h"
#include "clad/nse.h"

USING(clad_module, ns);

Then you can call the functions form the module abbreviated though the name space pointer like this:

int main(void) {
  ns->foo; /* In stead of clad_module_foo or clad_foo. */
}

This approach also has as the benefit that if you want to use a different implementation, that maintains the same API, only the USING statement needs to be modified.

Credits

  • Bjorn Reese for predef.h

  • Serge A. Zaitsev’s for jsmn

  • Sergey Lyubka for the foundations of slre.

Ideas

In ANSI C, data structures such as linked lists, hash tables, dynamic arrays, trees, etc can be implemented using different approaches with regards to the elements contained.

  1. Implement element-specific data structures. This is the most efficient but not reusable.

  2. Use macros to manipulate element specific data structures. This works but doesn’t always look very nice.

  3. Use x-macros to generate element specific data structures. This works well but also doesn’t look very nice.

  4. Use void * pointers to link to the generic elements. This could cause type problems if the user doesn’t take care.

  5. Do as 4. but write element-specific wrappers manually or though macros. This works well but has some overhead.

  6. Use integer indexes into an array or dynamic array of the elements. This is something I’d like to explore.

  7. Use intrusive data structures in which the element contains the structure node as opposed to a regular approach where the structure node links to the . This works nicely, but some C safety standards, such as MISRA C forbid the use of offsetof() which makes this approach not usable if such standards must be followed. I consider this a bug in those standards, but it’s not easy to change them so.

  8. Use variants. This is quite limited.

Since there is no absolutely perfect approach, clad may include several approaches for the various data structures.

License

The MIT License (MIT)

Copyright (c) 2014 Bjorn De Meyer.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

C Library for Algorithms and Data structures.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published