[CC += Martin]

Hi Paul,

On Sun, Dec 14, 2025 at 06:01:52PM -0800, Paul Eggert wrote:
> 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.

I don't know if GCC only uses [n] for diagnostics, or if it also does
optimizations based on it.  Martin probably knows.

Also, I'm not sure GCC does anything different with [static n] than with
[n], regarding optimizations (except for nonnull and n>0, of course).
Martin probably also knows.

> 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?

Yes.

> 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.

Yes.  Although, such programs are already nonsense, IMO.
People would do well revising that their uses of [n] are correct.

> 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),

Yes.

> 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.

As I said above, I'm not sure.  However, I'd blidnly bet that whatever
code GCC generates for [n], it also generates it for [static n].

> 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.


Have a lovely day!
Alex

-- 
<https://www.alejandro-colomar.es>

Attachment: signature.asc
Description: PGP signature

Reply via email to