From a5d1c6da7e5617c15dd729a7907fb38cc25c2e1b Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Sat, 24 Dec 2022 02:26:00 +0100 Subject: Add vectors --- examples/gevector.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 examples/gevector.c (limited to 'examples/gevector.c') diff --git a/examples/gevector.c b/examples/gevector.c new file mode 100644 index 0000000..e554005 --- /dev/null +++ b/examples/gevector.c @@ -0,0 +1,25 @@ +#include +#include + +#include + +GEVECTOR_API(int, ivec); +GEVECTOR_IMPL(int, ivec); + +int +main(void) +{ + struct ivec *vec = malloc(sizeof(struct ivec)); + ivec_new(vec, 2, 0); + + ivec_append(vec, 42); + ivec_append(vec, 69); + ivec_append(vec, 420); + ivec_insert(vec, 1337, 2); + + for (size_t i = 0; i < vec->size; i++) + printf("%d\n", vec->items[i]); + + free(vec->items); + free(vec); +} -- cgit v1.2.3