Am Montag, dem 18.08.2025 um 23:19 +0000 schrieb Joseph Myers:
> On Fri, 15 Aug 2025, Alejandro Colomar wrote:
> 
> > Hi Joseph,
> > 
> > On Thu, Aug 14, 2025 at 10:03:00PM +0000, Joseph Myers wrote:
> > > On Thu, 14 Aug 2025, Alejandro Colomar wrote:
> > > 
> > > > And I'm proposing it as a GNU extension, which means we don't even need
> > > > to care about what ISO C says about [n].  We, as a quality
> > > > implementation, treat it with stronger semantics, which this patch uses.
> > > 
> > > As a GNU extension, it's also necessary to define semantics in the 
> > > presence of parameter forward declarations.
> > 
> > I'd say that if there are conflicting declarations the behavior is
> > undefined.  So, if you have [2] and [3], think again what you're doing.
> 
> We shouldn't introduce undefined behavior like that.  And the declarations 
> *aren't* conflicting under current language semantics.  It's the 
> introduction of this _Countof extension that has significant implications 
> for the conceptual model of how parameter declarations are handled in C 
> and introduces such a conflict.

Taking the size of the definition in _Countof seems largely orthogonal to
the question on how one deals with inconsistencies with forward declarations
of the function or parameters.  Forming a composite type could allow this
in even more cases later, but this seems unproblematic to add later. 

The only possible change in semantics I can see would be where a VLA becomes
a fixed  size array when forming a composite type, so the _Countof becomes 
a constant where it would now still be a run-time value. So while I agree
in general that we should be careful, I would not see this as a risky change
for GCC even when the other papers are subject to change or not adopted at all.

But I agree that it would make sense to have a complete discussion of this
topic before moving forward.


In the meantime, there are plenty of other things to do.  A step forward
could be to add warnings for the case when thesize of an array parameter
is inconsistent with a forward declaration.  Such warnings seem to be 
desirable in any case.  There are many other cases related to this general
areas where we still miss "obvious" warnings.

Martin


Reply via email to