Newsgroups: comp.text Path: utzoo!sq!msb From: msb@sq.sq.com (Mark Brader) Subject: Re: ISC 2.0.2 troff broke? (groff as well?) Message-ID: <1991Mar4.213407.16278@sq.sq.com> Summary: In troff, positive, rather than nonzero, is true in .if's Organization: SoftQuad Inc., Toronto, Canada References: <1434@vidiot.UUCP> <1435@vidiot.UUCP> <1991Feb27.221722.2213@mtxinu.COM> Date: Mon, 4 Mar 91 21:34:07 GMT Lines: 38 "Vidiot" asked why .if \nG==1&\nI==0 ... didn't work. Jaap Akkerhuis diagnosed correctly that Vidiot had forgotten troff's rather counterintuitive rule of no precedence, and suggested the following (or intended to suggest it, anyway; I have fixed a typo): > What you want to do, is to put the test in parentheses as in > .if (\nG==1)&(\nI==0) .tm condition is true And this is right. Jaap also observed that some people would say one of: > .if \nI==0 .if \nG==1 > .if !\nI .if \nG .tm true and that these are different if I and G are not really booleans. However, he falls from grace in saying that the second one is equivalent to the C code: > if( I != 0 && G == 0) First, the conditions are reversed, but again, that's incidental. The more important thing is this. In troff, when an integer value is treated as boolean, *only* a *positive* value is considered true. This is counterintuitive for C programmers, who are used to any nonzero value being considered true. The last line of troff above is thus actually equivalent to *this* in C: if (I <= 0 && G > 0) -- Mark Brader "The default choice ... is in many ways the most utzoo!sq!msb important thing. ... People can get started without msb@sq.com reading a big manual." -- Brian W. Kernighan This article is in the public domain.