[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] regex: use C99-style array arg syntax
From: |
Bruno Haible |
Subject: |
Re: [PATCH] regex: use C99-style array arg syntax |
Date: |
Fri, 27 Aug 2021 01:31:27 +0200 |
Paul Eggert wrote:
> +/* Specify the number of elements of a function's array parameter,
> + as in 'int f (int n, int a[__ARG_NELTS (n)]);'. */
> +#if (defined __STDC_VERSION__ && 199901L <= __STDC_VERSION__ \
> + && !defined __STDC_NO_VLA__)
> +# define __ARG_NELTS(n) n
> +#else
> +# define __ARG_NELTS(n)
> +#endif
The documentation of this macro makes it look like it expects an
expression as argument. But in the later uses you also often pass
the keyword 'static':
> + regmatch_t pmatch[__ARG_NELTS (static nmatch)],
> + regmatch_t prev_idx_match[__ARG_NELTS (static nmatch)],
How about changing the comment to
/* Specify the number of elements of a function's array parameter,
as in 'int f (int n, int a[__ARG_NELTS (n)]);'
or 'int f (int n, int a[__ARG_NELTS (static n)]);' */
By the way, what is the point of adding the 'static' keyword? From [1][2][3]
I understand that when one writes 'TYPE a[static n]' it denotes
a pointer to an array of at least n objects of type TYPE.
But since, for any m ≥ n, a pointer to m objects of type TYPE is also a
pointer to n objects of type TYPE, the words "at least" are redundant:
'TYPE a[static n]' denotes
a pointer to an array of n objects of type TYPE.
So, what does 'TYPE a[n]' denote, then?
- the same thing?
- or a pointer to one object of type TYPE, just like 'TYPE a[]'?
Either way, the syntax 'TYPE a[n]' (without 'static') in function parameter
declarations appears redundant. Correct?
In that case, shouldn't the comment be changed to
/* Specify the number of elements of a function's array parameter, together
with the 'static' keyword, as in
'int f (int n, int a[__ARG_NELTS (static n)]);' */
Bruno
[1] ISO C 11, § 6.7.6.3.(7)
[2] https://en.cppreference.com/w/c/language/array
[3]
https://stackoverflow.com/questions/17559631/what-are-those-strange-array-sizes-and-static-in-c99