From owner-svn-src-all@FreeBSD.ORG Mon Jan 11 13:44:13 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id CBBF2106566B; Mon, 11 Jan 2010 13:44:13 +0000 (UTC) (envelope-from des@des.no) Received: from smtp.des.no (smtp.des.no [194.63.250.102]) by mx1.freebsd.org (Postfix) with ESMTP id 552828FC0A; Mon, 11 Jan 2010 13:44:12 +0000 (UTC) Received: from ds4.des.no (des.no [84.49.246.2]) by smtp.des.no (Postfix) with ESMTP id F19FE1FFC22; Mon, 11 Jan 2010 13:44:11 +0000 (UTC) Received: by ds4.des.no (Postfix, from userid 1001) id C1E3A844CC; Mon, 11 Jan 2010 14:44:11 +0100 (CET) From: =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= To: Bruce Evans References: <201001081544.o08FinVh015359@svn.freebsd.org> <20100109073716.E57804@delplex.bde.org> Date: Mon, 11 Jan 2010 14:44:11 +0100 In-Reply-To: <20100109073716.E57804@delplex.bde.org> (Bruce Evans's message of "Sat, 9 Jan 2010 07:56:10 +1100 (EST)") Message-ID: <86aawkzrh0.fsf@ds4.des.no> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.95 (berkeley-unix) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Edward Tomasz Napierala Subject: Re: svn commit: r201794 - in head/sys: ddb dev/ep dev/ex netinet6 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Jan 2010 13:44:13 -0000 Bruce Evans 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 : #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