> On Aug 21, 2024, at 17:54, Bill Wendling <isanb...@gmail.com> wrote: > >> if (__builtin_get_counted_by(p->array)) { >> size_t max_value = >> type_max(typeof(*__builtin_get_counted_by(p->array))); >> if (count > type_max) >> ...fail cleanly... >> *__builtin_get_counted_by(p->array) = count; >> } >> >> I don't strictly need to READ the value (but it seems nice). Currently I can >> already do a READ with something like this: >> >> size_t count = __builtin_dynamic_object_size(p->array, 1) / >> sizeof(*p->array); >> >> But I don't have a way to examine the counter _type_ without >> __builtin_get_counted_by, so I prefer it over __builtin_set_counted_by. >> > Another thing to point out, the documented type signature of > __builtin_get_counted_by() is more-or-less meaningless. It should be > adjusted during SEMA to a pointer to the count's type. It's only "void > *" if the 'counted_by' attribute.
For GCC’s implementation, the returned type of the __builtin_get_counted_by is: The TYPE of the returned value must be a pointer type pointing to the corresponding type of the counted-by object or a VOID pointer type in case of a NULL pointer being returned. Qing > > -bw