Date: Mon, 11 Jan 2010 14:44:11 +0100 From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no> To: Bruce Evans <brde@optusnet.com.au> Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Edward Tomasz Napierala <trasz@FreeBSD.org> Subject: Re: svn commit: r201794 - in head/sys: ddb dev/ep dev/ex netinet6 Message-ID: <86aawkzrh0.fsf@ds4.des.no> In-Reply-To: <20100109073716.E57804@delplex.bde.org> (Bruce Evans's message of "Sat, 9 Jan 2010 07:56:10 %2B1100 (EST)") References: <201001081544.o08FinVh015359@svn.freebsd.org> <20100109073716.E57804@delplex.bde.org>
next in thread | previous in thread | raw e-mail | index | archive | help
Bruce Evans <brde@optusnet.com.au> writes: > All of these bugs should have been avoided by using normal style. KNF > doesn't even use the "!" operator for testing simple booleans! Older > KNF code in kern uses comparisions with 0 fairly consistently for testing > flags in a bitmap being 0. Even the not-so-old KNF code in kern that > tests the not-so-old flag TDF_SINTR does this (there is only one instance, > in kern_sig.c, where the above is spelled correctly as > ((td->td_flags & TDF_SINTR) =3D=3D 0). I like to use ! for testing even = sets > of flags so I prefer the above, but this is not KNF. > > Spelling for testing the opposite sense is more mixed. Omitting the > !=3D 0 seems to be most common. ISTR that 1) the rule is "don't use it as a predicate unless the name clearly marks it as such" and 2) it isn't actually written down anywhere... TD_IS_SLEEPING(td) is clearly a predicate, so it's OK not to compare it explicitly with 0; (td->td_flags & TDF_SINTR) may well be a predicate, but this is not obvious from a quick glance at the code, so there should be an explicit comparison. The canonical example is strcmp(), which is *not* a predicate, but is often used (and easily misused) as one. It almost makes me want to add the following to <string.h>: #define streq(s1, s1) (strcmp((s1), (s2)) =3D=3D 0) #define strlt(s1, s1) (strcmp((s1), (s2)) < 0) #define strgt(s1, s1) (strcmp((s1), (s2)) > 0) (or the equivalent static inline functions to avoid double expansion issues) DES --=20 Dag-Erling Sm=C3=B8rgrav - des@des.no
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?86aawkzrh0.fsf>