[PATCH evdev] type-safe inline functions for bitmask manipulation
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 & (1 << 30)
> > BitIsOn(ptr, KEY_A): ((BYTE*)ptr) & (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) & (1 << 6).
> Another simpler example:
> long a = 0x04030201;
> ((unsigned char*)&a) == 0x04
> ((unsigned char*)&a) == 0x03
> ((unsigned char*)&a) == 0x02
> ((unsigned char*)&a) == 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
070f30e..4969389 master -> master
More information about the xorg-devel