From e72088d79804e4f689196f4bc700fb9348c77209 Mon Sep 17 00:00:00 2001 From: Carson Fleming Date: Sat, 24 Jan 2026 22:28:22 -0500 Subject: initial commit --- array.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 array.c (limited to 'array.c') diff --git a/array.c b/array.c new file mode 100644 index 0000000..c941b05 --- /dev/null +++ b/array.c @@ -0,0 +1,26 @@ +#include "array.h" +#include "crash.h" +#define CRASH_IF_OOB(array, idx) {\ + if (idx >= array->length)\ + crash("Array access out of bounds: %ld >= %ld\n", idx, array->length);\ +} + +void array_set(array_t* array, size_t idx, void* val) { + CRASH_IF_OOB(array, idx); + array->data[idx] = val; +} + +void* array_get(const array_t* array, size_t idx) { + CRASH_IF_OOB(array, idx); + return array->data[idx]; +} + +void str_set(str_t* str, size_t idx, char val) { + CRASH_IF_OOB(str, idx); + str->data[idx] = val; +} + +char str_get(const str_t* str, size_t idx) { + CRASH_IF_OOB(str, idx); + return str->data[idx]; +} -- cgit v1.2.3