double exclamation mark meaning ?

Yann Droneaud ydroneaud at opteya.com
Thu Dec 6 05:05:27 EST 2012


> Hi,
>
> # define likely(x)  __builtin_expect(!!(x), 1)
> # define unlikely(x)    __builtin_expect(!!(x), 0)
>
> I see these !! in the above expressions. Please explain me the
> meaning of those double exclamations. What is their significance ?
>

This is a kind of cast to a "bool".

After applying !!(x), the value will be either 0 or 1.
It's roughly equivalent to (((x) != 0) ? 1 : 0)

Regards.

-- 
Yann Droneaud
OPTEYA





More information about the Kernelnewbies mailing list