James Kuyper
3/18/2011 10:33:00 PM
On Friday, March 18, 2011 5:53:25 PM UTC-4, Michael Press wrote:
> int main(void)
> {
> ---3;
> return 0;
> }
>
> error: invalid lvalue in decrement
>
> ???
> Why does this have to be an error?
> The value could be -4 or -3 or -2.
> If somebody [shuffles feet] wants
> to use this construction, then who
> would stop him?
There is, for some reason that I've never understood, a popular misconception, mostly possessed only by newbies, that --x is another way of saying x-1.. I can make sense of your comment only by assuming that have this misconception. That misconception would convert ---3 into -3-1, which would, of course, be perfectly legal, and have a value of -4.
In reality, --x is another way of saying x = x-1, except that 'x' is only evaluated once.
If the constraint requiring that the right operand of the -- operator be a modifiable lvalue (6.5.3.1p1) were removed, then according to 6.5.3.3p1, the meaning of ---3 would be -3 -= 1. That would violate the contraint that the left operand of a assignment operator be a modifiable lvalue (6.5.16p2). If that constraint were also removed, then according to 6.5.16.2p3, the meaning of -3 -= 1 would be the same as -3 = -3 - 1, except that -3 would be evaluated only once.
So, what precisely is it you would like -3 = -3 - 1 to do? What exactly would it mean to assign a new value to -3?
How do you feel about ---x? Should that be legal too? What would it mean? Please think about that carefully before answering.