[Mesa-dev] [PATCH kmscube] texturator: Use !! for boolean assignment

Jason Ekstrand jason at jlekstrand.net
Tue Mar 31 20:38:58 UTC 2020


On Tue, Mar 31, 2020 at 3:00 PM Ian Romanick <idr at freedesktop.org> wrote:
>
> On 3/31/20 12:25 PM, Fabio Estevam wrote:
> > The 'complemented' variable is a pointer to boolean. Use the !! operator
> > to fix the following build warning:
> >
> > ../texturator.c:603:45: warning: '*' in boolean context, suggest '&&' instead [-Wint-in-bool-context]
> >   *complemented = (((float)rgba[2]) / 255.0) / 0.25;
> >
> > Signed-off-by: Fabio Estevam <festevam at gmail.com>
> > ---
> >  texturator.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/texturator.c b/texturator.c
> > index a450dfe..d31b601 100644
> > --- a/texturator.c
> > +++ b/texturator.c
> > @@ -602,7 +602,7 @@ static void extract_pix(uint8_t *rgba, int *slice, int *level, bool *complemente
> >  {
> >       *slice = (((float)rgba[0]) / 255.0) * 8.0;
> >       *level = (((float)rgba[1]) / 255.0) * 16.0;
> > -     *complemented = (((float)rgba[2]) / 255.0) / 0.25;
> > +     *complemented = !!(((float)rgba[2]) / 255.0) / 0.25;
>
> I don't know how others feel, but I know Matt hates this idiom.  I'm not
> terribly fond of it either.  I think we both prefer either casting to
> bool or x != 0.0.  But... I don't feel that strongly.

My feelings aren't usually all that strong on this point though I
generally prefer !=.  That said, this is a float.  I very strongly
prefer != 0.0f.


More information about the mesa-dev mailing list