[PATCH v7 14/14] linux/termios: regression test for termios speed functions

Adhemerval Zanella Netto adhemerval.zanella@linaro.org
Tue Jun 10 19:00:34 GMT 2025



On 10/06/25 15:24, H. Peter Anvin wrote:
> On 2025-06-10 11:21, H. Peter Anvin wrote:
>> On 2025-06-10 11:11, H. Peter Anvin wrote:
>>>
>>> How would you feel about this addition to <array_length.h> (as a separate patch)? I have found these to be incredibly useful macros in a lot of contexts...
>>>
>>
>> Actually working version, and probably better named. If people think this is a good idea I'll submit it as a proper patch as part of v8.
>>
>>      -hpa
> 
> diff --git a/include/array_length.h b/include/array_length.h
> index 2305e211b210..75db8e1a2743 100644
> --- a/include/array_length.h
> +++ b/include/array_length.h
> @@ -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 */

Seems a good addition to me, I'm ccing Paul/Bruno since this header is shared with
gnulib and they might have some comments whether this would fit gnulib as well.


More information about the Libc-alpha mailing list