Re: A pettiness question.

From: Andrea Arcangeli
Date: Wed Sep 21 2005 - 04:30:34 EST


On Wed, Sep 21, 2005 at 02:01:11PM +0500, Fawad Lateef wrote:
> On 9/21/05, Ustyugov Roman <dr_unique@xxxxxx> wrote:
> > > Hi, All.
> > >
> > > I found there are use double operator ! continuously sometimes in
> > > kernel.
> > > e.g:
> > >
> > > static inline int is_page_cache_freeable(struct page *page)
> > > {
> > > return page_count(page) - !!PagePrivate(page) == 2;
> > > }
> > >
> > > Who would like tell me why write like above?
> >
> > For example,
> >
> > int test = 5;
> > !test will be 0, !!test will be 1.
> >
> > This give a enum of {0,1}. If test is not 0, !!test will give 1, otherwise 0.
> >
> > Am I right?
>
> Yes, but what abt the above case/example ??? PagePrivate is defined as
> test_bit and test_bit will return 0 or 1 only ...... So y there is (
> !! ) ??

Note that gcc should optimize it away as long as the asm*/bitops is
doing "return something != 0" like most archs do.

Most of the time test_bit retval is checked against zero only, here it's
one of the few cases where it's required to be 1 or 0. If you audit all
archs then you can as well remove the !! from above.

Thanks!
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/