[PATCH evdev] type-safe inline functions for bitmask manipulation

Peter Hutterer peter.hutterer at who-t.net
Sun Oct 23 23:25:23 PDT 2011


On Wed, Oct 19, 2011 at 09:34:47AM +0200, Max Schwarz wrote:
> > EvdevBitIsSet(array, KEY_A):    array[0] & (1 << 30)
> 
> > BitIsOn(ptr, KEY_A):            ((BYTE*)ptr)[3] & (1 << 6)
> That is true on little-endian. Big-endian machines have that byte in position 
> 0, so that one would need to be ((BYTE*)ptr)[0] & (1 << 6).
> 
> Another simpler example:
> 
> long a = 0x04030201;
> 
> Big-endian:
> ((unsigned char*)&a)[0] == 0x04
> ((unsigned char*)&a)[1] == 0x03
> ((unsigned char*)&a)[2] == 0x02
> ((unsigned char*)&a)[3] == 0x01
> 
> It's weird because we're used to developing on little-endian ;-)
> AFAIK the fact that casting to shorter types "just works" is one of the 
> reasons why little-endian is used everywhere.
> 
> This wouldn't be a problem if we exclusively used SetBit/BitIsOn everywhere. 
> But we get the bitmask from the kernel, which uses longs and uses correct byte 
> order...


  070f30e..4969389  master -> master

thanks

Cheers,
  Peter


More information about the xorg-devel mailing list