[PATCH evdev] Don't crop long value from EvdevBitIsSet.

Peter Hutterer peter.hutterer at who-t.net
Wed Nov 2 14:13:34 PDT 2011


On Wed, Nov 02, 2011 at 02:31:33PM +0100, walter harms wrote:
> 
> 
> Am 02.11.2011 14:15, schrieb Chase Douglas:
> > On 11/02/2011 07:29 AM, walter harms wrote:
> >>
> >>
> >> Am 02.11.2011 00:52, schrieb Peter Hutterer:
> >>> Introduced in xf86-input-evdev-2.6.0-26-g4969389
> >>>
> >>> Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
> >>> ---
> >>> Cutting long to int for the return value loses us some values, notably in
> >>> the ABS_MT ranges.
> >>>
> >>>  src/evdev.c |    2 +-
> >>>  1 files changed, 1 insertions(+), 1 deletions(-)
> >>>
> >>> diff --git a/src/evdev.c b/src/evdev.c
> >>> index f593df0..6ab1a18 100644
> >>> --- a/src/evdev.c
> >>> +++ b/src/evdev.c
> >>> @@ -190,7 +190,7 @@ static size_t EvdevCountBits(unsigned long *array, size_t nlongs)
> >>>  
> >>>  static inline int EvdevBitIsSet(const unsigned long *array, int bit)
> >>>  {
> >>> -    return array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS));
> >>> +    return !!(array[bit / LONG_BITS] & (1LL << (bit % LONG_BITS)));
> >>>  }
> >>>  
> >>>  static inline void EvdevSetBit(unsigned long *array, int bit)
> >>
> >> hi,
> >> i have never seen that !! notation. perhaps (array == 0) would be more readable and
> >> not suprise to much people ?
> > 
> > I would like to echo this. I actually don't know what the '!!' does
> > here. Since this is a one-off issue, can you add a comment to explain
> > what it is doing?
> > 
> 
> IMHO the following happens:
> 
> The first ! translates 0  (type long) into !0 (type int)
> and translates !0 (type long) into 0 (type int)
> 
> Now you have int but the logic is reversed, so you need a second !

That question has come up in the past:
http://lists.x.org/archives/xorg-devel/2010-November/015942.html

for any numeric value x, !!x is the boolean equivalent of that
numeric value, 0 for x == 0 and 1 for x != 0 (technically !0 I guess but
practically it's 1).

We're already using this in a few places, e.g. BitIsOn(). It's quite common
with plenty of instances in e.g. mesa or the kernel (the two repos I quickly
grepped for it).

Cheers,
  Peter


More information about the xorg-devel mailing list