Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!nic.MR.NET!thor!mike From: mike@thor.stolaf.edu (Mike Haertel) Newsgroups: comp.lang.c Subject: Re: Compiler Error? Summary: not an error Keywords: "?:" precedence cc pcc assignment 43BSD SunOS Message-ID: <1196@thor.stolaf.edu> Date: 17 Feb 89 02:19:49 GMT References: <683@sbsvax.UUCP> Reply-To: mike@stolaf.edu Organization: St. Olaf College; Northfield, MN Lines: 24 In article <683@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes: >Consider the following program: ... > (j = 2) ? k = 3 : 4; ... >According to the C books I could get my hands on, >"?:" has higher precedence than the assignment operators, like >"=" for instance. (In X3J11 too) > >Thus the compiler should find an error in the statement, something >like "misplaced assignment". No. That this works is not an error. Precedence rules are used to resolve ambiguity about which of two neighboring operators an expression belongs to. In this case, the assignment statement is in the middle of an operator, so to speak, so there is no ambiguity. >PS.: I found such a statement in GNU grep, when I was porting it to SINIX. Don't send a bug report about GNU grep because I won't change it just for the benefit of some brain damaged compiler without a proper parser. Mike Haertel