Hi Joseph, > Date: 2026-10-09 20:11:59+0000 > From: Joseph Myers <[email protected]> > > On Fri, 9 Oct 2026, Alejandro Colomar wrote: > > > Joseph, would it be acceptable to you to have it unspecified? > > You could do that *with documentation and tests*. (That includes testing > with different values for the two length expressions that the result is > one of the values, in various cases with both constant, both variable or > one constant and one variable. Also in cases where one gives a length and > one uses []. Also in cases where one gives a length and one declares it > as a pointer.)
Sure!! Thank you very much! Sounds like an agreement! :-)
Documentation and tests are of course appropriate.
> In the latter two cases, you'd need to be clear in the
> documentation about whether it's guaranteed valid, or guaranteed invalid -
> or unspecified whether it's valid or not in the case where some
> declarations give a length and some don't, but I don't like that option of
> being unspecified affecting validity rather than just which length
> expression is chosen.
Agree.
With my current implementation, it doesn't yet accept it as valid, but
I'll try to figure out how to do that.
alx@debian:~/tmp/cap$ cat test.c
int f(int (*p)[42]; int (*p)[])
{
return _Countof(*p);
}
int g(int a[42]; int a[])
{
return _Countof(a);
}
int main(void)
{
int a[42];
return f(&a) + g(a);
}
alx@debian:~/tmp/cap$ /opt/local/gnu/gcc/cap/bin/gcc test.c
test.c: In function ‘g’:
test.c:7:24: error: invalid application of ‘_Countof’ to incomplete
type ‘int[]’
7 | return _Countof(a);
| ^
Martin, do you happen to remember any difference in the implementation
of array parameters (vs. pointers to array) that makes this
unnecessarily different at the moment? It seems pointers to array are
appending, while array parameters are overwriting.
TBH, I'm surprised that pointers to array work. I was expecting they'd
similarly shadow and forget the length expression.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
