Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Problem with ()?():() as ending test in for-loop Message-ID: <17757@mimsy.UUCP> Date: 25 May 89 21:39:12 GMT References: <17722@mimsy.UUCP> <344.nlhp3@oracle.nl> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 29 >In article <17722@mimsy.UUCP> I claimed that >>[logical] e1?e2:e3 expression[s] can ... be transformed ... into >>(e1&&e2)||e3 In article <344.nlhp3@oracle.nl> bengsig@oracle.nl (Bjorn Engsig) writes: >No Chris, this was a bit too fast. If e1!=0 and e2==0, (e1&&e2)||e3 evaluates >e3 and returns it's truth value, whereas (e1?e2:e3) returns 0 and does not >evaluate e3. Oops, right. I think my brain was on fire when I wrote <17722@mimsy.UUCP>. But e1?e2:e3 *can* be turned into (e1&&e2 || !e1&&e3) [&& has higher precedence than ||, but you should parenthesise in real code]: e1 e2 e3 e1?e2:e3 e1&&e2 !e1&&e3 e1&&e2||!e1&&e3 -- -- -- -------- ------ ------- --------------- F F F F F F F F F T T F T T F T F F F F F F T T T F T T T F F F F F F T F T F F F F T T F T T F T T T T T T F T (where F = false = 0, and T = true = nonzero-in 1-out). The ultimate test for boolean operations is to draw up a truth table.... -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris