Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: lvalues from the ternary op Date: Wed, 04 Jan 2017 14:20:57 -0800 Organization: None to speak of Lines: 40 Message-ID: References: <8737kned1h.fsf@bsb.me.uk> <8737klapvv.fsf@bsb.me.uk> <877f6alefh.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="167f7d05f22907ea8e3985ed50c4ed73"; logging-data="28834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/d8mZxP2xYPK9sSEcmHAfH" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:xks8ciuFUliKWGas429Su5IsdYs= sha1:Otiju1jvFsR80uuvCkpTlF6JXTQ= Xref: csiph.com comp.lang.c:101142 Ian Collins writes: > On 01/ 5/17 10:48 AM, Keith Thompson wrote: >> Ben Bacarisse writes: >> [...] >>> But I don't think that gets us any closer to knowing what might or might >>> not be "reasonable" in C. The C standard enumerates all the expression >>> forms that are lvalues and, as in the case of x.y for example, it >>> sometimes depends on whether one or other part of the expression is >>> itself an lvalue. So there's no obvious reason that it could not say >>> that a conditional expression is an lvalue if both arms are lvalue >>> expressions. >> >> And of the same type, or perhaps compatible types would be sufficient. >> >> For example, this: >> >> int x; >> double y; >> (condition ? x : y) = 42; >> >> would be difficult to implement sensibly. Taking the address of a >> ternary expression would be even more difficult. (C++ already does >> this; I haven't checked the standard's wording.) > > Does it? Perhaps "does this" was ambiguous. What I meant is that in C++, given: int i1, i2; double x; (condition ? i1 : i2) is an lvalue, but (condition ? i1 : x) is not. I verified this by compiling a couple of small test programs (with a ternary expression on the LHS of an assignment) with g++. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"