|Luiserebii 61a5717b78 Making (void) function parameter explicit||2 weeks ago|
|.circleci||1 month ago|
|include||2 weeks ago|
|scripts||1 month ago|
|test||3 weeks ago|
|.clang-format||1 month ago|
|.gitattributes||1 month ago|
|.gitignore||1 month ago|
|LICENSE||1 month ago|
|README.md||1 month ago|
Implementation of the C++ Standard Library in C. Can creatures armed without wings engage in flight?
Functions from the
<algorithm> header are currently being implemented as macros, often requiring an explicit passing of the type being used. For more, check out algorithm.h.
Emulating the C++
<vector> in C is difficult, but macros allow us some room to play. Two macros,
define_vector, allow us to explicitly provide a type (much like a template) and construct the rest according to our needs.
Since the declaration of the vector
struct data type and associated functions should ideally belong in a header file, it is advised to use the
declare_vector within one, and use
define_vector in a matching
.c file. For example, to create an
int vector, one might write:
/** vector_int.h **/ #ifndef VECTOR_INT_H #define VECTOR_INT_H #include "vector.h" declare_vector(int) #endif
/** vector_int.c **/ #include "vector_int.h" #include "vector.h" define_vector(int)
This will then expand into the appropriate vector
vector_int) with matching functions. All functions are appended with the type, with the general format
vector_FUNCTION_TYPE. Therefore, to
push_back on an
int vector, one would call
vector relies on dynamically-allocated memory via
malloc, a convenience function
vector_free_TYPE has been provided to release a vector after it has finished being used.
Further documentation on the currently implemented functions can be found in vector.h.
test/ directory contains tests which intend to exercise typical usage. To run all tests, simply use the command
make test, which also includes diagnostic information from valgrind to ensure resources are being freed properly. The simple test framework Unity is currently being used to write them.
This code has been licensed under the GNU General Public License v3.0.