On 2025-12-14 16:30, Alejandro Colomar wrote:
Hi Paul,
On Sun, Dec 14, 2025 at 02:00:05PM -0800, Paul Eggert wrote:
On 2025-12-14 13:18, Alejandro Colomar wrote:
In GNU C, [n] means you can
access the first n elements.
Oh, I didn't know that. Where is this documented? I looked in the GCC manual
but couldn't find it.
There's <https://gcc.gnu.org/onlinedocs/gcc/Variable-Length.html>, but
it doesn't say much. It's essentially an undocumented feature.
Agreed. That part of the documentation is about variable-length arrays,
which are (to some extent) an orthogonal feature.
Also, how can one tell that GNU C supports this extension? Is there a sample
program illustrating the support?
Yup, here's one:
The examples you gave are only about what diagnostics GCC generates.
Does this mean the change you're proposing is a new constraint? That is,
it'll be a new part of the standard where the compiler is required to
issue a diagnostic, and where behavior is undefined if the constraint is
violated?
If so, this isn't an *extension* to C23/C17/etc.; it's a new
*restriction*: some valid C23/C17/etc. programs will become invalid in
C2y. And if I understand things correctly, currently GCC issues some
diagnostics not required by C23 (which the standard of course allows; a
compiler can issue whatever diagnostics it likes), but GCC goes ahead
and generates code that conforms to C23, that is, its optimizer doesn't
take advantage of the new constraint that I hypothesized above.
Am I on the right track here?
Part of the reason I'm asking, is I'm wondering if Gnulib should attempt
to package this sort of thing up. Our past experience in doing that
(vla.h) was a failure, and I'm reluctant to attempt anything unless I
fully understand the direction you're proposing.
The problem is that UB propagates backwards, so that
you can observe it even before it has been triggered.
Sure, but that's fine in all the places where Gnulib is using nonnull
attributes. Callers are not supposed to pass a NULL filename to
functions like execl, ever. And we rely on static checking to check
that. This is not an unusual or undesirable situation.