Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!pitstop!sundc!seismo!uunet!mcvax!hp4nl!tnoibbc!westc!gjoost From: gjoost@westc.UUCP (Gertjan van Oosten) Newsgroups: comp.lang.c Subject: Re: Compiler Error? Keywords: "?:" precedence cc assignment Message-ID: <441@westc.UUCP> Date: 16 Feb 89 11:30:13 GMT References: <683@sbsvax.UUCP> Reply-To: gjoost@westc.UUCP (Gertjan van Oosten) Organization: West Consulting bv, Delft, The Netherlands Lines: 41 In article <683@sbsvax.UUCP> greim@sbsvax.UUCP (Michael Greim) writes: >Consider the following program: ... > (j = 2) ? k = 3 : 4; ... >On 43BSD, SunOS 3.4, ULTRIX 2.0 this compiles with no error. > >According to the C books I could get my hands on, >"?:" has higher precedence than the assignment operators, like >"=" for instance. (In X3J11 too) Your quote from the C-books is right, but you should read it more carefully: "?:" has higher precedence than assignment. ^ +--- spot the colon there! So this means, that an expression like: a = b ? c : d is parsed as: a = (b ? (c) : d) "?:" is a ternary operator, with operands b, c and d (assuming that b and d don't contain unparenthesised expressions containing lower precedence operators). >Thus the compiler should find an error in the statement, something >like "misplaced assignment". No, it shouldn't. >SIEMENS SINIX v2.1 finds an error. Siemens SINIX v2.1 is an error. :-) Yours sincerely, G. J. van Oosten. "Peace on earth and mercy mild, Mother Brown has lost her child. Just another forgotten son....." Marillion, "Forgotten Sons"