Date: Thu, 7 Mar 2002 15:53:15 -0500 From: Leo Bicknell <bicknell@ufp.org> To: Garance A Drosihn <drosih@rpi.edu> Cc: "Brian T.Schellenberger" <bts@babbleon.org>, 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> In-Reply-To: <p05101508b8ad7b67c653@[128.113.24.47]> References: <52204.1015480748@critter.freebsd.dk> <20020307071630.E26DBBA03@i8k.babbleon.org> <p05101508b8ad7b67c653@[128.113.24.47]>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020307205315.GA21048>