Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ernie.Berkeley.EDU!jas From: jas@ernie.Berkeley.EDU (Jim Shankland) Newsgroups: comp.lang.c Subject: Re: Compiler Error? Keywords: "?:" precedence cc pcc assignment 43BSD SunOS Message-ID: <28033@ucbvax.BERKELEY.EDU> Date: 15 Feb 89 17:03:41 GMT References: <683@sbsvax.UUCP> Sender: usenet@ucbvax.BERKELEY.EDU Reply-To: jas@ernie.Berkeley.EDU.UUCP (Jim Shankland) Organization: University of California, Berkeley Lines: 21 In article <683@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes: >This is about pre-ANSI C. > > [Is the following legal C?] > (j = 2) ? k = 3 : 4; I.e., is the assignment statement between the ? and the : legal, given that = has lower precedence than ?:. This issue comes up periodically. The answer is unclear. K & R doesn't rightly say whether this is legal, though people have made casuistic arguments on both sides. I *will* note that it's unambiguous and easily parsable, so perhaps there's no reason to disallow it. No doubt the pANS has resolved this one way or the other. Meanwhile, I claim: if you're writing a compiler, allow it; if you're writing code, don't use it. Jim Shankland jas@ernie.berkeley.edu "I've been walking in a river all my life, and now my feet are wet"