diff options
| author | Carson Fleming <[email protected]> | 2026-01-24 22:28:22 -0500 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2026-01-24 22:28:22 -0500 |
| commit | e72088d79804e4f689196f4bc700fb9348c77209 (patch) | |
| tree | 195e8b20cf633a0b9fc2ef6754c08742a9ce30e1 /array.c | |
| download | safec-e72088d79804e4f689196f4bc700fb9348c77209.tar.gz | |
initial commit
Diffstat (limited to 'array.c')
| -rw-r--r-- | array.c | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -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]; +} |
