From 9a7f7b5ec4033b83bbde8a7347895994e7aad6c4 Mon Sep 17 00:00:00 2001 From: Anony Moose Date: Sat, 24 Aug 2013 21:45:45 +0000 Subject: Added array for loop. --- testing/misc_tools.h | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'testing/misc_tools.h') diff --git a/testing/misc_tools.h b/testing/misc_tools.h index 0ffd51e7..7c37ba38 100644 --- a/testing/misc_tools.h +++ b/testing/misc_tools.h @@ -153,6 +153,16 @@ static inline void tox_array_pop(tox_array *arr, uint32_t num) arr->data = realloc(arr->data, arr->elem_size*arr->len); } -#define tox_array_get(arr, i, type) ((type*)(arr)->data)[i] +#define tox_array_get(arr, i, type) (((type*)(arr)->data)[i]) -#endif // MISC_TOOLS_H +/* TODO: what about nested for loops? */ +#define tox_array_for_each(arr, type) \ + for ( \ + struct { type tmp; uint32_t i; } tox_array_tmp = { tox_array_get(arr, 0, type), 0 }; \ + tox_array_tmp.i != (arr)->len; \ + tox_array_tmp.tmp = tox_array_get(arr, ++tox_array_tmp.i, type) \ + ) + +#define TOX_ARRAY_TMP (tox_array_tmp.tmp) + +#endif // MISC_TOOLS_H \ No newline at end of file -- cgit v1.2.3