Re: [PATCH: 1/1] sh4: avoid spurious gcc warning

From: Geert Uytterhoeven
Date: Mon Jan 23 2023 - 09:50:01 EST


Hi Jakub,

On Sun, Jan 22, 2023 at 1:47 PM Jakub Jelinek <jakub@xxxxxxxxxx> wrote:
> On Sun, Jan 22, 2023 at 12:33:41PM +0100, Michael Karcher wrote:
> > Am 22.01.2023 um 08:00 schrieb Randy Dunlap:
> > > > -#define _INTC_ARRAY(a) a, __same_type(a, NULL) ? 0 : sizeof(a)/sizeof(*a)
> > > > +#define _INTC_ARRAY(a) a, sizeof(a)/(_Generic((a), typeof(NULL): 0xFFFFFFFFU, default: sizeof(*a)))
> > > s/: / : / in 2 places.
> > >
> > > Tested-by: Randy Dunlap <rdunlap@xxxxxxxxxxxxx> # build-tested
> >
> > Thanks for your confirmation! Are you sure about the space before the colon?
>
> No, it should be without those, see various other _Generic uses in
> include/linux/
> All those are formatted on one line for each case, so for the above macro it
> would be
> #define _INTC_ARRAY(a) (a), sizeof(a)/(_Generic((a), \
> typeof(NULL): -1, \
> default: sizeof(*(a)))
> or so.
> Anyway, two comments:
> 1) I'd use -1 as that would be after promotion to size_t the largest size_t
> unlike 0xFFFFFFFFU; of course, as for the void * case a can't be an array,
> any value > sizeof(void*) will do

Or SIZE_MAX.

include/linux/limits.h:#define SIZE_MAX (~(size_t)0)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds