Skip to content

ephf/vector.h

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vector.h

Easy to use C vector library using [] for array-like access.

To use, download the vector.h file and include it in your c project. Define the VEC_IMPL header where you want your implementions.

Examples

#define VEC_IMPL
#include "vector.h"
#include <assert.h>

int main() {
    vector(int) numbers = vec(1, 2, 3);

    assert(numbers[1] == 2);

    push(&numbers, 4);
    assert(numbers[3] == 4);
    assert(len(numbers) == 4);

    remv(&numbers, 2);
    int compare[] = { 1, 2, 4 };
    assert(memcmp(compare, numbers, sizeof(int[3])) == 0);

    freevec(numbers);
}
#define VEC_IMPL
#include "vector.h"
#include <assert.h>

int main() {
    vector(const char*) names = 0;

    push(&names, "John");
    ins(&names, "Doe", 2);

    const char* compare[] = { "John", NULL, "Doe" };
    assert(memcmp(compare, names, sizeof(const char*[3])) == 0);

    pop(&names);
    assert(len(names) == 2);

    freevec(names);
}

Extra

Feel free to support and use this library (see LICENSE). You can run unit tests with the following make config:

$ make test

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published