Hi Joseph, On Fri, Jan 16, 2026 at 01:06:41AM +0100, Alejandro Colomar wrote: > Hi Joseph, > > On Thu, Jan 15, 2026 at 11:33:10PM +0000, Joseph Myers wrote: > > On Thu, 15 Jan 2026, Alejandro Colomar wrote: > > > > > I recently discovered that we wouldn't be introducing and new undefined > > > behavior. That same undefined behavior already exists today in GCC 16: > > > > You can't deduce UB from how the compiler behaves on this particular > > input. You need to specify the semantics so that then we can see if there > > is UB either explicitly or implicitly. > > Hmmmm, then we should document the behavior of _Countof() in GCC 16 for
Actually, not even a GCC 16 or _Countof() thing. This happened with
sizeof() before too.
alx@devuan:~/tmp$ cat cap.c
int
f(int n, char a[][n]; int n, char a[][n+1])
{
return sizeof(a[0]);
}
int
main(void)
{
char a[42];
return f(42, &a);
}
alx@devuan:~/tmp$ gcc -Wall -Wextra cap.c
alx@devuan:~/tmp$ ./a.out
alx@devuan:~/tmp$ echo $?
43
> pointers to arrays when interacting with forward declarations of
> parameters, right?
>
> Then, array parameters would just be consistent with that.
>
> That makes sense to me.
>
> Should I document it as part of _Countof() or as part of forward
> declarations of parameters? Do you have any preference?
It should be documented as part of forward declarations of parameters,
as this is not inherent to _Countof().
Have a lovely day!
Alex
--
<https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
