Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #94200

Re: lvalues from the ternary op

From BartC <bc@freeuk.com>
Newsgroups comp.lang.c
Subject Re: lvalues from the ternary op
Date 2016-09-28 18:23 +0100
Organization A noiseless patient Spider
Message-ID <nsgua2$jom$1@dont-email.me> (permalink)
References <c8677aed-7589-4ba4-9aa0-8b20b00c0981@googlegroups.com> <8737kned1h.fsf@bsb.me.uk> <kfnk2dxc89h.fsf@x-alumni2.alumni.caltech.edu> <8737klapvv.fsf@bsb.me.uk> <2bb1903b-4f4d-235e-dd9c-ff8e559b83bb@verizon.net>

Show all headers | View raw


On 28/09/2016 17:39, James R. Kuyper wrote:
> On 09/27/2016 07:23 PM, Ben Bacarisse wrote:
>> Tim Rentsch <txr@alumni.caltech.edu> writes:
>>
>>> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
> ...
>>>> C++ allows you to write (d ? y : x) += F(CF); directly.  I'm not sure
>>>> why C doesn't, but it seems a shame to me that it doesn't.
>>>
>>> Does it?
>>
>> Yes it does.
>>
>>> The pattern is one that IME hardly ever comes up (not
>>> never, but certainly rarely).  Adding the two &'s and one * is
>>> not very burdensome (and might be done using a macro to make the
>>> idiom stand out more, if that is desired).  I don't see how a
>>> form like this generalizes to other cases (to emphasize, in C -
>>> in C++ it might be different).
>
> The key feature of C++ that makes this work is relatively simple, and
> could be translated into the C context without much trouble. In C terms,
> it basically says that if both the second and third operands of ?: are
> lvalues of the same type, then the result is an lvalue of that type.


That isn't much different from this:

   int *p;
   int cond;
   int a,b;

   p = (cond ? &a : &b);

The two pointer expressions need to match.

-- 
bartc

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

lvalues from the ternary op luser droog <luser.droog@gmail.com> - 2016-09-25 16:12 -0700
  Re: lvalues from the ternary op "James R. Kuyper" <jameskuyper@verizon.net> - 2016-09-25 19:58 -0400
  Re: lvalues from the ternary op Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-26 01:10 +0100
    Re: lvalues from the ternary op Tim Rentsch <txr@alumni.caltech.edu> - 2016-09-27 15:01 -0700
      Re: lvalues from the ternary op Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-09-28 00:23 +0100
        Re: lvalues from the ternary op BartC <bc@freeuk.com> - 2016-09-28 01:35 +0100
        Re: lvalues from the ternary op "James R. Kuyper" <jameskuyper@verizon.net> - 2016-09-28 12:39 -0400
          Re: lvalues from the ternary op BartC <bc@freeuk.com> - 2016-09-28 18:23 +0100
        Re: lvalues from the ternary op Tim Rentsch <txr@alumni.caltech.edu> - 2016-10-08 15:37 -0700
  Re: lvalues from the ternary op supercat@casperkitty.com - 2016-09-25 18:14 -0700
  Re: lvalues from the ternary op BartC <bc@freeuk.com> - 2016-09-26 10:51 +0100
    Re: lvalues from the ternary op luser droog <luser.droog@gmail.com> - 2016-09-26 12:42 -0700

csiph-web