View Single Post
  #22 (permalink)  
Old 03-09-2012, 06:17 PM
Keith Thompson
Guest
 
Posts: n/a
Default Re: Legality of a++ = 1 ?

"BartC" <bc@freeuk.com> writes:
> "Keith Thompson" <kst-u@mib.org> wrote in message
> news:lnpqcm4zuz.fsf@nuthaus.mib.org...
>> Harald van Dijk <haraldvdijk@gmail.com> writes:
>>> [ Legality of a++ = 1 ]

>
>>> No, it's always a value. If you can come up with a concrete sane
>>> proposal for making a++ an lvalue and a description of what the
>>> semantics should be, preferably without breaking existing valid code,
>>> I will be very impressed.

>>
>> For what it's worth, in C++ ++a is an lvalue (but a++ isn't).

>
> How would the ++a work? Like this:
>
> int a=1000;
>
> ++a += 3; // a is now 1004?


I get 1004 using the g++ compiler -- but as in C, modifying an object
twice without an intervening sequence point has undefined behavior.

I think the usefulness of allowing ++a to be an lvalue shows up when
"++" is an overloaded operator.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Will write code for food.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Reply With Quote