Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ames!ncar!tank!uxc!uxc.cso.uiuc.edu!a.cs.uiuc.edu!m.cs.uiuc.edu!kenny From: kenny@m.cs.uiuc.edu Newsgroups: comp.lang.c Subject: Re: possible operator precedence bug? Message-ID: <4700018@m.cs.uiuc.edu> Date: 6 Oct 88 17:08:00 GMT References: <751@mcrware.UUCP> Lines: 37 Nf-ID: #R:mcrware.UUCP:751:m.cs.uiuc.edu:4700018:000:1419 Nf-From: m.cs.uiuc.edu!kenny Oct 6 12:08:00 1988 /* Written 6:17 pm Oct 4, 1988 by jejones@mcrware.UUCP in m.cs.uiuc.edu:comp.lang.c */ /* ---------- "possible operator precedence bug?" ---------- */ [... expression that looks like] | | M[Z]=Z[ ? , , "_." : " |"]; | |The question is this: why does this make it through the compiler at all? |K&R says that the comma operator has the lowest priority, so shouldn't |the following be required for the code to correctly parse? | | M[Z]=Z[ ? (, , "_.") : " |"]; | ^ ^ /* End of text from m.cs.uiuc.edu:comp.lang.c */ The precedence rules are used only when needed to resolve ambiguity among two syntactically correct parses of the same sentence. The use of the comma between the query and the colon is unambiguous, and the precedence rules do not come into play. The relative precedence of ?: and , is used is in ambiguous contexts like: x = ( a , b ? c : d ); and x = ( a ? b : c , d); where the higher precedence of ? : causes the statements to be interpreted as x = ( a , ( b ? c : d ) ); and x = ( ( a ? b : c ) , d ); respectively. Kevin Kevin Kenny UUCP: {uunet,pur-ee,convex}!uiucdcs!kenny Department of Computer Science ARPA Internet or CSNet: kenny@CS.UIUC.EDU University of Illinois 1304 W. Springfield Ave. Urbana, Illinois, 61801 Voice: (217) 333-6680