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


Groups > comp.lang.c > #94175

Re: lvalues from the ternary op

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: lvalues from the ternary op
Date 2016-09-28 00:23 +0100
Organization A noiseless patient Spider
Message-ID <8737klapvv.fsf@bsb.me.uk> (permalink)
References <c8677aed-7589-4ba4-9aa0-8b20b00c0981@googlegroups.com> <8737kned1h.fsf@bsb.me.uk> <kfnk2dxc89h.fsf@x-alumni2.alumni.caltech.edu>

Show all headers | View raw


Tim Rentsch <txr@alumni.caltech.edu> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>
>> luser droog <luser.droog@gmail.com> writes:
>>
>>> Just came up with this.  Probably foolish nonsense as usual.
>>
>> No, I think its a reasonable thing to do.  C++ thought so too, to the
>> extent of making it easier.  But its not technically "lvalues from the
>> ternary op".  It's just lvalues from the * op -- the result of a *
>> expression is always an lvalue.
>>
>>> I was looking over the (obfuscated) code of my 8086 emulator
>>> and my eyes fell upon this statement.
>>>
>>> https://github.com/luser-dr00g/8086/blob/b7bfb134c1146cbe2ac7f1b80dd521e0ddb2349c/a8086.c#L112
>>> d?y+=*fl&CF:(x+=*fl&CF);
>>>
>>> And I thought:  There's a lot of repetition in the two cases.
>>> So what about:
>>>
>>> *(d?&y:&x)+=F(CF);
>>
>> 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).  To me it looks like the two
> cost/benefit ratios weigh in favor of how C is now.  So perhaps
> I don't understand what you consider the respective costs and
> benefits are in the two cases.

I consider special cases to be a sort of intellectual cost.  But my
remark about it being a shame is not intended to be a considered
weighing-up of hard engineering costs but simply a sad observation on
there being yet another exception I would not have expected.  If I did
not know better, I would assume that that any expression that could
reasonably be a lvalue would be an lvalue.

I would have liked (in some alternate universe where the engineering
costs had already been incurred) to see the result of assignments be
lvalues (as they are in C++) as well as the result of a comma operator
(as it is in C++) and prefix -- and ++ (as they are in C++[1]).

I don't really know how to evaluate the costs, but I would probably
still consider it a shame, even if I were sure it were so for sound
economic reasons.

[1] Only to a first approximation.  C++ has a more complex menagerie of
    value kinds than C does.

-- 
Ben.

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