[PATCH] include: let BitIsOn() return a boolean value.

Peter Hutterer peter.hutterer at who-t.net
Wed Nov 24 20:57:21 PST 2010


On Wed, Nov 24, 2010 at 08:23:45PM -0600, Pat Kane wrote:
> Okay, with that info and if you could make the macro something like this:
> 
>  #define BitIsOn(ptr, bit) (!!(((BYTE *) (ptr))[(bit)>>3] & (1 <<
> ((bit) & 7))))  /* !! converts to boolean */

tbh, I'd rather not explain C constructs in comments unless really really
necessary. We currently have 18 occurances of !! in the server code, not
counting the above, running 'git grep "\!\![(a-zA-z].*;" | wc -l' in the
kernel shows 1843 (about a third of those are enthusiastic printfs). so it's
not really an uncommon expresssion.

Cheers,
  Peter

> 
> then:
> 
> Reviewed: Pat Kane <pekane52 at gmail.com>
> 
> Pat
> ----
> P.S.  I love C, it is my favorite assembly code.  -- PEK
> 
> 
> On Wed, Nov 24, 2010 at 4:28 PM, Peter Hutterer
> <peter.hutterer at who-t.net> wrote:
> > On Wed, Nov 24, 2010 at 12:18:16PM -0600, Pat Kane wrote:
> >> What the deal with the "!!" operator?  I read it as a double logical negation.
> >> A NOOP,  does it have some useful side effect?
> >
> > http://stackoverflow.com/questions/1406604/what-does-the-operator-double-exclamation-point-mean-in-javascript
> > is the first link I found.
> >
> > yes, I used to think it was dirty too, but I've grown to like it.
> >
> > Cheers,
> >  Peter
> >>
> >> On Wed, Nov 24, 2010 at 10:30 AM, walter harms <wharms at bfs.de> wrote:
> >> >
> >> >
> >> > Am 24.11.2010 07:25, schrieb Keith Packard:
> >> >> On Wed, 24 Nov 2010 14:40:11 +1000, Peter Hutterer <peter.hutterer at who-t.net> wrote:
> >> >>
> >> >>> -#define BitIsOn(ptr, bit) (((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
> >> >>> +#define BitIsOn(ptr, bit) !!(((BYTE *) (ptr))[(bit)>>3] & (1 << ((bit) & 7)))
> >> >>
> >> >
> >> > bit is checked to be less than 8 with "(bit) & 7" but only in the second statement.
> >> > the linux kernel specifies them as inline code. maybe this is the way to go here also.
> >> >
> >> > re,
> >> >  wh
> >
> 


More information about the xorg-devel mailing list