On Wed, Aug 21, 2024 at 05:43:42PM +0200, Martin Uecker wrote:
> Am Mittwoch, dem 21.08.2024 um 15:24 +0000 schrieb Qing Zhao:
> > > 
> > > But if we changed it to return a void pointer,  we could make this
> > > a compile-time check:
> > > 
> > > auto ret = __builtin_get_counted_by(__p->FAM);
> > > 
> > > _Generic(ret, void*: (void)0, default: *ret = COUNT);
> > 
> > Is there any benefit to return a void pointer than a SIZE_T pointer for
> > the NULL pointer? 
> 
> Yes! You can test with _Generic (or __builtin_types_compatible_p)
> at compile-time based on the type whether you can set *ret to COUNT
> or not as in the example above.
> 
> So it is not a weird run-time test which needs to be optimized
> away.

I don't have a strong opinion here, but I would tend to agree that
returning "void *" is a better signal that it is not valid. And I do
really like the _Generic example there, which makes it even easier to do
the "set if counted_by" action.

-- 
Kees Cook

Reply via email to