[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: when source code isn't enough




Hi Peter,

> also, i'm wondering if !! is a double negation or something about C which
> i've never learned:
> 
> #define input_report_key(a,b,c) input_event(a, EV_KEY, b, !!(c))
> 
> if it's a double negation, what possible purpose could it serve?

The logical not operator in C takes an expression, evaluates if it is
true, and then inverses the result, guaranteeing an answer of 0 or 1.

    !0 => 1
    !1 => 0
    !7 => 0

Since logical not is right associative, !!e is equivalent to !(!(e)) so
the result of !e, 0 or 1, is passed through ! again yielding another
guaranteed 0 or 1.

    !!0 => 0
    !!1 => 1
    !!7 => 1

It's a common idiom for getting 0 or 1 depending on whether the
expression is false or true.


Ralph.

-
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.surriel.com/kernelnewbies.shtml