nasmlib.h: add convenience macros for iterating over fixed arrays

Iterating over fixed arrays is a common operation; add macros to
simplify the task.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2025-09-04 17:09:57 -07:00
parent e0d5333a47
commit 61b525fbc1

View file

@ -309,6 +309,10 @@ const char *filename_set_extension(const char *inname, const char *extension);
* the number of elements of a statically defined array.
*/
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
#define ARRAY_END(arr) (&(arr)[ARRAY_SIZE(arr)])
#define array_for_each(var,arr) \
for ((var) = (arr); (var) < ARRAY_END(arr); (var)++)
/*
* List handling