Re: [PATCH v2 9/9] iio: adc: ad4062: Add GPIO Controller support
From: Andy Shevchenko
Date: Thu Dec 04 2025 - 17:22:09 EST
On Thu, Dec 4, 2025 at 11:38 PM Jorge Marques <gastmaier@xxxxxxxxx> wrote:
> On Thu, Nov 27, 2025 at 11:20:54AM +0200, Andy Shevchenko wrote:
> > On Wed, Nov 26, 2025 at 04:55:41PM +0100, Jorge Marques wrote:
> > > On Mon, Nov 24, 2025 at 12:40:37PM +0200, Andy Shevchenko wrote:
> > > > On Mon, Nov 24, 2025 at 10:18:08AM +0100, Jorge Marques wrote:
...
> > > > > + return reg_val == AD4062_GP_STATIC_HIGH ? 1 : 0;
> > > >
> > > > return !!(reg_val == AD4062_GP_STATIC_HIGH);
> > > >
> > > > also will work.
> > > >
> > > return reg_val == AD4062_GP_STATIC_HIGH;
> >
> > Hmm... This will include implicit bool->int. The !! guarantees values 0 or 1,
> > but I don't remember about implicit bool->int case.
> I don't think the implicit bool->int is an issue, grepping `return .* == .*;`
> matches a few methods that return int.
Yes, the Q here is the value of true _always_ be promoted to 1?
> Experimenting with the _Bool type (gcc 15, clang 19, any std version),
>
> int main()
> {
> int a = 1;
> int b = 2;
>
> return (_Bool)(a == b);
> }
>
> with
> gcc -Wall -W -pedantic -std=c23 -c test.c
> clang -Wall -Wextra -Wbool-conversion -std=c11 -O2 test.c
>
> also doesn't raise warnings.
Of course, because before even looking into warnings the entire code
degrades to return 0. I.o.w., the test case is not correct. But don't
hurry up to fix it, you won't get warnings anyway, it's all about C
standard and not about (in)correctness of the code. See above.
--
With Best Regards,
Andy Shevchenko