Woodrow Douglass a écrit :
Bob Beers wrote:
On Mon, May 11, 2009 at 5:22 PM, Robert P. J. Day <rpj...@crashcourse.ca> wrote:
On Mon, 11 May 2009, Bob Beers wrote:

On Mon, May 11, 2009 at 5:00 PM, RT Mistler <rtmist...@techen.com> wrote:
Hi,

I've been looking at some kernel modules trying to map an embedded
devices resources and while going through a driver, I encountered an
"if" test that employed "!!", example:

if !!function_foo(args) {
 ...
}

What does the "!!" do? (I'm familiar with a single "!")
IIANM, it does "!" and then does "!" again, forcing boolean value,
true or false.
 it's not clear why that would make any difference since 0 is boolean
false and everything else is boolean true.  so under what
circumstances would doing a double negation change execution
behaviour?  or am i missing something?


Well, the OP's example is not a real example from the kernel source.
A usage I can imagine is where one requires a *boolean* value,
not just "0" or "not 0". This usage, "!!", provides that conversion, no?

-Bob
In my experience, saying "if (!!x)" produces cleaner assembly on some architectures than "if (x)". Your mileage may vary.
Yes I think it is similar to what the "likely" macro defines :

http://lxr.linux.no/linux+v2.6.29/include/linux/compiler.h#L105

Christophe

-Woody

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ




--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecar...@nl.linux.org
Please read the FAQ at http://kernelnewbies.org/FAQ

Reply via email to