Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!munnari.oz.au!csc!ccadfa!usage!basser!metro!bunyip!moondance!uqcspe!qfagus!anvil!michi
From: michi@anvil.oz (Michael Henning)
Newsgroups: comp.lang.c
Subject: Re: precedence of ?:
Summary: Brackets are needed
Message-ID: <658@anvil.oz>
Date: 14 Sep 89 22:41:39 GMT
References: <1265@gmdzi.UUCP>
Organization: Anvil Designs Pty Ltd, Brisbane, Australia
Lines: 33

In article <1265@gmdzi.UUCP>, wittig@gmdzi.UUCP (Georg Wittig) writes:
> 
> How should
> 	0 ? 0 : i = 0
> be interpreted?
> 
> 1)	as	(0) ? (0) : (i=0)
> 	resulting in a (strange but) legal expression
> 
> or 2)	as	(0 ? 0 : i) = 0
> 	resulting in a syntax error
> ?
> 

The correct interpretation is

	(0 ? 0 : i) = 0

because the precedence of ':' is higher than that of '='. Compilers which
accept '0 ? 0 : i = 0' as correct are simply wrong. I strongly recommend
the book

	"C A Reference Manual" by Harbison and Steele (Prentice Hall)

for the answers to problems such as the one above. It is the best reference
text for C I have seen so far.

					Michi.
-- 
| Michael Henning            |  Internet   : michi@anvil.oz{.au}              |
| Anvil Designs              |  JANET      : michi%anvil.oz@uk.ac.ukc         |
| P.O. Box 954               |  ARPA,Bitnet: michi%anvil.oz.au@uunet.uu.net   |
| Toowong 4066, Australia    |  UUCP       : ...!uunet!munnari!anvil.oz!michi |