Hi Martin, On Sun, Aug 04, 2024 at 07:38:49AM GMT, Martin Uecker wrote: > Am Sonntag, dem 04.08.2024 um 01:17 +0200 schrieb Alejandro Colomar: > > > > FUTURE DIRECTIONS: > > > > We could make it work with array parameters to functions, and > > somehow magically return the length designator of the array, > > regardless of it being really a pointer. > > And maybe flexible array members with "counted_by" attribute.
Hmmm; I didn't know that one. Indeed. I'll have a look at implementing
that in this patch set.
> > +
> > +/* Implement the lengthof keyword: Return the length of an array,
> > + that is, the number of elements in the array. */
> > +
> > +tree
> > +c_lengthof_type (location_t loc, tree type)
> > +{
> > + enum tree_code type_code;
> > +
> > + type_code = TREE_CODE (type);
> > + if (!COMPLETE_TYPE_P (type))
> > + {
> > + error_at (loc,
> > + "invalid application of %<lengthof%> to incomplete type %qT",
> > + type);
> > + return error_mark_node;
> > + }
> > + if (type_code != ARRAY_TYPE)
> > + {
> > + error_at (loc, "invalid application of %<lengthof%> to type %qT",
> > type);
> > + return error_mark_node;
> > + }
>
> I would swap these two errors, because the first is more specific and
> less helpful if you pass an incomplete struct, where it would be better
> to get the second error.
Agree.
BTW, I still don't understand what `if (! TYPE_DOMAIN (type))` means,
within array_type_nelts_minus_one(). What code triggers that condition?
Am I missing error handling for that? Thanks!
Have a lovely day!
Alex
>
> Martin
>
> > +
> > + return array_type_nelts_top (type);
> > +}
>
--
<https://www.alejandro-colomar.es/>
signature.asc
Description: PGP signature
