diff options
Diffstat (limited to 'include/array_length.h')
-rw-r--r-- | include/array_length.h | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/include/array_length.h b/include/array_length.h index da1a700..2a4f09f 100644 --- a/include/array_length.h +++ b/include/array_length.h @@ -1,5 +1,5 @@ /* The array_length and array_end macros. - Copyright (C) 2017-2024 Free Software Foundation, Inc. + Copyright (C) 2017-2025 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -33,4 +33,18 @@ VAR must evaluate to an array, not a pointer. */ #define array_end(var) (&(var)[array_length (var)]) +/* array_foreach (PTR, ARRAY) iterates over all the elements in an + array, assigning the locally defined pointer variable PTR to each + element in turn. + + array_foreach_const (PTR, ARRAY) does the same, but *PTR is declared + const even if the array is not. */ +#define array_foreach(ptr, array) \ + for (__typeof ((array)[0]) *ptr = (array) ; \ + ptr < array_end (array) ; ptr++) + +#define array_foreach_const(ptr, array) \ + for (const __typeof ((array)[0]) *ptr = (array) ; \ + ptr < array_end (array) ; ptr++) + #endif /* _ARRAY_LENGTH_H */ |