Date: Wed, 6 Mar 2002 01:49:26 +0200 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Julian Elischer <julian@elischer.org> Cc: hackers@freebsd.org Subject: Re: RFC: style(9) isn't explicit about booleans for testing. Message-ID: <20020305234926.GA6839@hades.hell.gr> In-Reply-To: <Pine.BSF.4.21.0203051255520.26829-100000@InterJet.elischer.org> References: <20020305201350.GC4820@hades.hell.gr> <Pine.BSF.4.21.0203051255520.26829-100000@InterJet.elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2002-03-05 12:59, Julian Elischer wrote:
>
> On Tue, 5 Mar 2002, Giorgos Keramidas wrote:
> > >
> > > Read the man page to try and decide if you should write "if (x)" or
> > > if (x != 0).
> > >
> > > >Fix:
> > >
> > > Apply the attached page to the style(9) man page.
> [...]
>
> the one that I stop to think about is:
>
> if (!(flags & FLAGSET))
>
> or should that be
>
> if ((flags & FLAGSET) == 0)
>
> it depends on what you define as a Boolean.
>
> If FLAGSET has > 1 bit in it then it it still possibly a boolean?
I was reading parts of the sys/netinet tree lately. Most of the
places I have seen so far use the second style, even for flags that
are stored in bitfields. Quoting ip_input.c:
if ((m->m_pkthdr.rcvif->if_flags & IFF_LOOPBACK) == 0) {
ipstat.ips_badaddr++;
goto bad;
}
This is what I prefer too, but my own personal preference is probably
based on what I've seen so far, which is (I have to admit) very limited.
Giorgos Keramidas FreeBSD Documentation Project
keramida@{freebsd.org,ceid.upatras.gr} http://www.FreeBSD.org/docproj/
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020305234926.GA6839>
