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 18:31:26 -0800 Organization: None to speak of Lines: 36 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="823e57597edb8da97e8f43b1b8c9fed4"; logging-data="30151"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ecm0DErvhtz1BDrTmcUns" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:yCeCgAeFoEQ82CQ23DtEE4EuTfk= sha1:RNUBw3mY98+ps0+MPmxgPElzWpQ= Xref: csiph.com comp.lang.c:101152 ram@zedat.fu-berlin.de (Stefan Ram) writes: > supercat@casperkitty.com writes: >>Under the existing rules, it wouldn't be an lvalue, but that the whole >>point of this discussion is how things might behave if the language were >>changed to allow for ternary expressions to yield lvalues. > > In C++, it is an lvalue. So you just might check out C++. The point is that whether it's an lvalue only if the second and third operands are lvalues *and* have the same type (not just compatible types). C++11 5.16 [expr.cond] paragraphs 4 and 5: If the second and third operands are glvalues of the same value category and have the same type, the result is of that type and value category and it is a bit-field if the second or the third operand is a bit-field, or if both are bit-fields. Otherwise, the result is a prvalue. I think this could be adapted for C with a few tweaks: "glvalues" --> "lvalues" "value category" can probably be dropped "the result is a prvalue" --> "the expression is not an lvalue" (Allowing a conditional expression to be an value if the second and third operands are not of exactly the same type is not, in my opinion, worth the effort.) -- 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"