From -8239521972637510163
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,20d4605c5c59d328
X-Google-Attributes: gidf78e5,public
From: "Bill Wade" <bill.wade@stoner.com>
Subject: Re: Operator precedence
Date: 1998/01/30
Message-ID: <6aqsd6$h3d$1@uuneo.neosoft.com>#1/1
X-Deja-AN: 320707728
References: <34D0D0B5.BFB28C88@utsw.swmed.edu>
X-Original-Date: Thu, 29 Jan 1998 15:30:12 -0600
Originator: austern@isolde.mti.sgi.com
X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4
Organization: NeoSoft, Inc.
X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBNNJocky4NqrwXLNJAQHrfgIAre1Pph3S+koiHwyPjZaBnGs/RIDb32PX PO2oW4Jb17XFV1FNK00aHO3EICh7WAnPY6HAKg1RNGMpv2h12Jlpxg== =dxAW
Newsgroups: comp.std.c++


Zhiming Zhou wrote in message <34D0D0B5.BFB28C88@utsw.swmed.edu>...
>In many books, including "The C++ Programming language, 2ed" (pp. 90),
>conditional operator (? :) has higher precedence than assignment (=).
>However, in the book "The C++ Programming language, 3ed" (pp. 121), it's
>the other way around. Can somebody tell me why?

The answer is not symmetric.  The conditional operator has a higher
precedence than an assignment on its left.  It has a lower precedence than
an assignment on its right.  It has a lower precedence than anything (even a
comma expression) in its middle.

The meaning of
  a = b ? c = d : e = f;
is
  a = ( b ? (c=d) : (e = f) )

So ?: has a higher precedence than the assignment on the left, but lower
precedence than the assignment on the right.

This may be clearer from the grammar

conditional-exp:
    logical-or-exp:
    logical-or-exp ? exp : assignment-exp

assignment-exp:
    conditional-exp
    logical-or-exp assignment-operator assignment-exp
    throw-exp

exp:
    assignment-exp
    exp,assignment-exp

In the example above there is no parenthesis around
  (a=b)
because the left argument of ?: cannot be an assignment.  There must be
parenthesis around (e=f) because the left argument of assignment may not be
a conditional.

Ignoring the middle argument I think you'd be correct in saying that
assignment and conditional have the same precedence and bind right to left.
---
[ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
                newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]



