Hi Joseph,

> Date: 2026-10-08 18:55:44+0000
> From: Joseph Myers <[email protected]>
>
> On Thu, 8 Oct 2026, Alejandro Colomar wrote:
> 
> > > My suggestion would be to be strict on the new feature (e.g. disallow 
> > > _Countof for any parameter for which both a forward declaration and 
> > > another declaration of the parameter are visible) rather than adding 
> > > extra 
> > > checks for consistency of forward parameter declarations.
> > 
> > That'd be unacceptable for me.  I need to be able to use _Countof() on
> > arrays that have been forward declared.
> > 
> > Here's are a couple of examples:
> > 
> >     char *
> >     vseprintf(char dst[], const char end[];
> >         char dst[dst?end-dst:0], const char end[0], const char *restrict 
> > fmt, va_list ap)
> 
> Then the strict semantics could be for e.g. using _Countof for a parameter 
> where a forward declaration gives an array length.

I find that ok.

Another (simpler, but which is a breaking change) would be to disallow
the use of array length expressions in forward declarations.

> > But we could have a different constraint which I'd find acceptable:
> > 
> > -  Disallow declaring any array length expressions within a forward
> >    declaration of a parameter.
> > 
> >     void f(int a[42]; int a[]);     // constraint violation
> >     void g(int a[42]; int a[42]);   // constraint violation
> >     void g(int a[]; int a[42]);     // ok
> 
> I think restricting the new feature in such cases would be better than 
> restricting forward declarations themselves in such cases.

Ok.  I have some concerns about having _Countof invalidate a certain
expression that would otherwise be fine.  But I also see the point in
keeping backwards compatibility, so I accept the compromise.

Let's say it's disallowed to take the _Countof() of an array whose
length expression has appeared in a forward declaration.

Would you (or Martin) mind helping me implement that?  I'm pretty much
lost about how to do it.  I guess we should have a flag or something
that tells whether this has happened, but I lack the knowledge of the
internals needed to do this, I fear.

Anyway, I can start by documenting that it's not allowed to do that.


Have a lovely night!
Alex

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

Attachment: signature.asc
Description: PGP signature

Reply via email to