diff options
| author | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-25 01:30:14 -0400 |
|---|---|---|
| committer | Riley Beckett <rbeckettvt@gmail.com> | 2025-10-25 01:30:14 -0400 |
| commit | 8003084ccf17b26e932b565cfc0bb30302af3dd7 (patch) | |
| tree | 34047d2451886d89ca16cfc23e0df4cd9122cbba /array.h | |
| parent | c6326009faf8f30e74e177b25f5b34c89520ee8c (diff) | |
array_dump macro is amazing
Diffstat (limited to 'array.h')
| -rw-r--r-- | array.h | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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_ |
