From 43f06890e2689af2ef54c4480fe5790692a24f65 Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Wed, 11 Oct 2023 10:04:04 -0600 Subject: deprecate common lisp solutions and write c; it's too much effort to keep up with the requirements for an archive. --- inc/macros.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 inc/macros.h (limited to 'inc/macros.h') diff --git a/inc/macros.h b/inc/macros.h new file mode 100644 index 0000000..841084d --- /dev/null +++ b/inc/macros.h @@ -0,0 +1,41 @@ +#include +#include +#include + +#ifndef MACROS_H +#define MACROS_H + +#define DEFINE_ARRAY(TYPE) \ + typedef struct { \ + TYPE *data; \ + size_t size; \ + } Array_##TYPE + +#define InitArray(TYPE, ...) \ + ({ \ + TYPE temp[] = __VA_ARGS__; \ + Array_##TYPE *arr = malloc(sizeof(Array_##TYPE)); \ + arr->size = sizeof(temp) / sizeof(temp[0]); \ + arr->data = malloc(arr->size * sizeof(TYPE)); \ + if (arr->data) { \ + memcpy(arr->data, temp, arr->size * sizeof(TYPE)); \ + } \ + arr; \ + }) + +#define InitArrayWithSize(TYPE, SIZE, INIT_VALUE) \ + ({ \ + Array_##TYPE *arr = malloc(sizeof(Array_##TYPE)); \ + arr->size = SIZE; \ + arr->data = malloc(arr->size * sizeof(TYPE)); \ + if (arr->data) { \ + for (size_t i = 0; i < arr->size; i++) \ + arr->data[i] = INIT_VALUE; \ + } \ + arr; \ + }) + +#define c_max(x, y) (((x) >= (y)) ? (x) : (y)) +#define c_min(x, y) (((x) <= (y)) ? (x) : (y)) + +#endif // MACROS_H -- cgit v1.3