2002-01-13 12:06:27

by 520047054719-0001

[permalink] [raw]
Subject: ugly warnings with likely/unlikely

Hi,

if (likely(stru->pointer))

results in an ugly warning about using pointer as int.
Is there something that could be done against that ?

Regards
Oliver


2002-01-13 14:55:51

by Alan

[permalink] [raw]
Subject: Re: ugly warnings with likely/unlikely

> if (likely(stru->pointer))
>
> results in an ugly warning about using pointer as int.
> Is there something that could be done against that ?

if (likely(stru->pointer == NULL))

Perhaps ?

2002-01-13 15:08:12

by 520047054719-0001

[permalink] [raw]
Subject: Re: ugly warnings with likely/unlikely

On Sunday 13 January 2002 16:07, Alan Cox wrote:
> > if (likely(stru->pointer))
> >
> > results in an ugly warning about using pointer as int.
> > Is there something that could be done against that ?
>
> if (likely(stru->pointer == NULL))
>
> Perhaps ?

That works. But it's so much work to type it.

Regards
Oliver

2002-01-13 17:28:14

by Andi Kleen

[permalink] [raw]
Subject: Re: ugly warnings with likely/unlikely

[email protected] (Oliver Neukum) writes:

> Hi,
>
> if (likely(stru->pointer))
>
> results in an ugly warning about using pointer as int.
> Is there something that could be done against that ?

Just use

if (!stru->pointer) {
...
}

instead. gcc and a lot of other compilers predict all pointer tests
against NULL as unlikely, unless you override that.

-Andi (who is a bit worried about the unlikelies multiplicating like rabbits)

2002-01-13 18:24:17

by Robert Love

[permalink] [raw]
Subject: Re: ugly warnings with likely/unlikely

On Sun, 2002-01-13 at 12:27, Andi Kleen wrote:

> -Andi (who is a bit worried about the unlikelies multiplicating like rabbits)

Indeed. People need to realize unlikely is not a free ride.

Robert Love

2002-01-13 20:18:36

by Andrew Morton

[permalink] [raw]
Subject: Re: ugly warnings with likely/unlikely

Alan Cox wrote:
>
> > if (likely(stru->pointer))
> >
> > results in an ugly warning about using pointer as int.
> > Is there something that could be done against that ?
>
> if (likely(stru->pointer == NULL))
>

-#define likely(x) __builtin_expect((x),1)
-#define unlikely(x) __builtin_expect((x),0)
+#define likely(x) __builtin_expect((x)!=0,1)
+#define unlikely(x) __builtin_expect((x)!=0,0)

?