aboutsummaryrefslogtreecommitdiff
path: root/array.h
diff options
context:
space:
mode:
authorRiley Beckett <rbeckettvt@gmail.com>2025-10-25 01:30:14 -0400
committerRiley Beckett <rbeckettvt@gmail.com>2025-10-25 01:30:14 -0400
commit8003084ccf17b26e932b565cfc0bb30302af3dd7 (patch)
tree34047d2451886d89ca16cfc23e0df4cd9122cbba /array.h
parentc6326009faf8f30e74e177b25f5b34c89520ee8c (diff)
array_dump macro is amazing
Diffstat (limited to 'array.h')
-rw-r--r--array.h11
1 files changed, 11 insertions, 0 deletions
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 <stdlib.h>
+#include <stdio.h>
#include <stdbool.h>
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_