From 8003084ccf17b26e932b565cfc0bb30302af3dd7 Mon Sep 17 00:00:00 2001 From: Riley Beckett Date: Sat, 25 Oct 2025 01:30:14 -0400 Subject: array_dump macro is amazing --- array.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'array.h') diff --git a/array.h b/array.h index 6ea74d7..852461c 100644 --- a/array.h +++ b/array.h @@ -1,6 +1,7 @@ #ifndef ARRAY_H_ #define ARRAY_H_ #include +#include #include typedef struct { @@ -77,4 +78,14 @@ void* array_resize_(void* array, size_t item_size, size_t size); type__* CONCAT(it__, __LINE__) = array__; type__* CONCAT(end__, __LINE__) = array__ ? array__ + array_size(array__) : NULL; \ for (type__* name__; (CONCAT(it__, __LINE__) < CONCAT(end__, __LINE__)) ? (name__ = CONCAT(it__, __LINE__), true) : false; CONCAT(it__, __LINE__)++) +#define array_dump(array, type, name, fmt, ...) do { \ + array_print(array); \ + fprintf(stderr, "vals: \n"); \ + type* it__ = (array); type* end__ = (array) ? (array) + array_size(array) : NULL; \ + for (type* name; it__ < end__ ? (name = it__, true) : false; it__++) { \ + fprintf(stderr, fmt", ", __VA_ARGS__); \ + } \ + fprintf(stderr, "\b\b \n"); \ +} while (0) + #endif // ARRAY_H_ -- cgit v1.2.3