Re: [PATCH v3 06/12] minmax: Introduce {min,max}_array()

From: Andy Shevchenko
Date: Tue Jun 13 2023 - 13:08:49 EST


On Tue, Jun 13, 2023 at 11:00 AM Herve Codina <herve.codina@xxxxxxxxxxx> wrote:
> On Mon, 12 Jun 2023 17:10:40 +0300
> Andy Shevchenko <andy.shevchenko@xxxxxxxxx> wrote:
> > On Mon, Jun 12, 2023 at 3:30 PM Herve Codina <herve.codina@xxxxxxxxxxx> wrote:
> > >
> > > Introduce min_array() (resp max_array()) in order to get the
> > > minimal (resp maximum) of values present in an array.
> >
> > Some comments below, after addressing them,
> > Reviewed-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>

...

> > > + typeof(array) __array = (array); \
> >
> > We have __must_be_array()
>
> Using __must_be_array() will lead to some failure.
> Indeed, we can have:
> --- 8< ---
> int *buff
> ...
> min = min_array(buff, nb_item);
> --- 8< ---
>
> In this case, __must_be_array() will report that buff is not an array.

Oh, I missed that.

> To avoid any confusion, what do you think if I renamed {min,max}_array()
> to {min,max}_buffer() and replace __array by __buff and use *(__buff + xxx)
> instead of array[xxx] in the macro.

But functionally it's still against an array.

I would stick with "array" in the name, but add a comment why
__must_be_array() is not used. If we need a stricter variant, we may
add a new wrapper with that check. That said, I think we can use
__array[0] and similar indexed accesses.


--
With Best Regards,
Andy Shevchenko