Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!mcsun!hp4nl!star.cs.vu.nl!maart From: maart@cs.vu.nl (Maarten Litmaath) Newsgroups: comp.lang.c Subject: Re: precedence of ?: (was: precedence of && (was: precedence of ?:)) Message-ID: <3269@solo5.cs.vu.nl> Date: 15 Sep 89 16:07:30 GMT References: <1265@gmdzi.UUCP> <11030@smoke.BRL.MIL> <11039@smoke.BRL.MIL> <3236@solo10.cs.vu.nl> <11045@smoke.BRL.MIL> <3242@solo12.cs.vu.nl> <11054@smoke.BRL.MIL> <3260@solo5.cs.vu.nl> <11069@smoke.BRL.MIL> Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 51 gwyn@smoke.BRL.MIL (Doug Gwyn) writes: \In article <3260@solo5.cs.vu.nl> maart@cs.vu.nl (Maarten Litmaath) writes: \>[... 0 ? 0 : i = 0 \>is accepted, whereas \> 0 && i = 0 \>is not.] \>But why allow the `?:' expression, why make it a special case? \ \I was mistaken in my original response; 0 ? 0 : i = 0 is not legal. Indeed! Yet both (SunOS 4.0.1) cc AND gcc 1.35 let it pass due to constant folding! :-( Let's see how this will do: $ cat c.c main() { int a, b, c, d; a = f(); b = g(); d = h(); test(a ? b : c = d); } $ cc -c c.c "c.c", line 9: illegal lhs of assignment operator $ gcc c.c ld: Undefined symbol _test _f _g _h $ \However, to save another iteration in this series of postings, note \that 0 ? i = 0 : 0 is legal. \ conditional-expression: \ logical-OR-expression \ logical-OR-expression ? expression : conditional-expression \So the interesting question becomes, why is that "expression" for the \second operand of ?: and not "logical-OR-expression". (I think that \"conditional-expression" might result in ambiguity.) [...] I don't think so: a ? b ? c : d : e has only one parse. (If "expression" is OK, "conditional-expression" surely is too!) Conclusion: cc has a small bug, gcc 1.35 has a more serious one. -- creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam: it shouldn't have existed at all. |maart@cs.vu.nl, mcvax!botter!maart