From owner-freebsd-hackers Tue Mar 5 12:14: 2 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from mailsrv.otenet.gr (mailsrv.otenet.gr [195.170.0.5]) by hub.freebsd.org (Postfix) with ESMTP id E154E37B404 for ; Tue, 5 Mar 2002 12:13:53 -0800 (PST) Received: from hades.hell.gr (patr530-a183.otenet.gr [212.205.215.183]) by mailsrv.otenet.gr (8.12.2/8.12.2) with ESMTP id g25KDoDg006808 for ; Tue, 5 Mar 2002 22:13:51 +0200 (EET) Received: from hades.hell.gr (hades [127.0.0.1]) by hades.hell.gr (8.12.2/8.12.2) with ESMTP id g25KDo0O004988 for ; Tue, 5 Mar 2002 22:13:50 +0200 (EET) (envelope-from keramida@freebsd.org) Received: (from charon@localhost) by hades.hell.gr (8.12.2/8.12.2/Submit) id g25KDoHG004987 for hackers@freebsd.org; Tue, 5 Mar 2002 22:13:50 +0200 (EET) (envelope-from keramida@freebsd.org) X-Authentication-Warning: hades.hell.gr: charon set sender to keramida@freebsd.org using -f Date: Tue, 5 Mar 2002 22:13:50 +0200 From: Giorgos Keramidas To: hackers@freebsd.org Subject: RFC: style(9) isn't explicit about booleans for testing. Message-ID: <20020305201350.GC4820@hades.hell.gr> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.27i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG The following is the largest part of the audit trail of PR docs/28555. At the end of the audit trail, Dima Dorfman asked Mike Meyer to seek review and comments from a wider audience than -doc. Since this documentation PR has been open for quit some time now, I'm posting the patch the PR was about, hoping to get comments from our style(9) meisters, and everyone else that can help with this. Giorgos Keramidas FreeBSD Documentation Project keramida@{freebsd.org,ceid.upatras.gr} http://www.FreeBSD.org/docproj/ --- Audit trail --- On 2001-06-30 21:26, Mike Meyer wrote: > The style(9) page says not to use ! for testing values unless the > value is a boolean. It also says to test pointers against NULL. This > leaves open the question of how other values that aren't booleans > should be tested. > > >How-To-Repeat: > > 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. > > --- /usr/src/share/man/man9/style.9 Fri May 18 07:27:37 2001 > +++ style.9 Sat Jun 30 16:23:34 2001 > @@ -449,14 +449,37 @@ > !(p = f()) > .Ed > .Pp > -Don't use '!' for tests unless it's a boolean, e.g. use > +For tests, always compare the value to the appropriate 0 instead of > +checking it directly, unless the value is a boolean. > +For pointers, use: > +.Bd -literal > +if (p != NULL) > +.Ed > +.Pp > +not > +.PP > +.Bd -literal > +if (!p) > +.Ed > +.Pp > +For other values, use: > .Bd -literal > if (*p == '\e0') > .Ed > .Pp > not > .Bd -literal > -if (!*p) > +if (*p) > +.Ed > +.Pp > +unless the value is a boolean. In that case, use: > +.Bd -literal > +if (p) > +.Ed > +.Pp > +and > +.Bd -literal > +if (!p) > .Ed > .Pp > Routines returning void * should not have their return values cast On 2002-06-30 21:57, Dima Dorfman wrote: > I think it is quite clear on the subject. If it's not a boolean, > don't treat it like one; i.e., compare it against the value you're > looking for. '0' may not always be that value. > > Regardless, this does not belong as a PR, let alone in the docs/ > category. It belongs as a post on -hackers, asking what people think, > not as a change request. Since *developers* are expected to follow > style(9), it is the *developers* (i.e., -hackers@) that you should be > proposing the change to. On 2001-06-30 22:55, Mike Meyer wrote: > We both agree I'm not proposing a change in the style they have to > follow; I'm just proposing making something explicit instead of > implicit. As such, I'm not sure it warrants discussion. If the PR > belongs in another category, please feel free to move it to either > move it or suggest one for someone else to move it to. On 2001-06-02 23:13, Dima Dorfman wrote: > I'm not suggesting that you should get every developer's approval, but > I am suggesting that wider review than the -doc list would be nice, > esp. for a document that defines policy. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message