From owner-freebsd-hackers Thu Mar 7 12:54:26 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from ussenterprise.ufp.org (ussenterprise.ufp.org [208.185.30.210]) by hub.freebsd.org (Postfix) with ESMTP id 2EC4037B416 for ; Thu, 7 Mar 2002 12:54:20 -0800 (PST) Received: (from bicknell@localhost) by ussenterprise.ufp.org (8.11.1/8.11.1) id g27KrFA21254; Thu, 7 Mar 2002 15:53:15 -0500 (EST) (envelope-from bicknell) Date: Thu, 7 Mar 2002 15:53:15 -0500 From: Leo Bicknell To: Garance A Drosihn Cc: "Brian T.Schellenberger" , hackers@FreeBSD.ORG Subject: Re: RFC: style(9) isn't explicit about booleans for testing -- an actual analysis of the code! Message-ID: <20020307205315.GA21048@ussenterprise.ufp.org> References: <52204.1015480748@critter.freebsd.dk> <20020307071630.E26DBBA03@i8k.babbleon.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: United Federation of Planets 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 In a message written on Thu, Mar 07, 2002 at 03:27:49PM -0500, Garance A Drosihn wrote: > As to the wording, PHK suggested that the wording for this > rule in style(9) be changed: > - - - > get rid of the word boolean, ie: change > Do not use ! for tests unless it is a boolean, e.g. use > to > Do not use ! for tests unless it is an integer type, e.g. use Although C doesn't have the type "boolean", I believe this is a conceptual distinction. That is, we don't want to allow this: if (!uid) { /* do thing only root can do */ } Because UID is not a boolean type. It takes a range of values, and should be: if (uid == 0) { /* do thing only root can do */ } The only proper use of "!" is on a boolean type, defined as a type that has two values, 0, and everything else. Personally, I would clarify boolean in the document as follows: C does not provide a proper boolean type. As a result, FreeBSD uses integers for a boolean type. The boolean values are 0 for false, and all other values for true. All code using a boolean type must not depend on "true" having any specific value. -- Leo Bicknell - bicknell@ufp.org - CCIE 3440 PGP keys at http://www.ufp.org/~bicknell/ Read TMBG List - tmbg-list-request@tmbg.org, www.tmbg.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message