[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c

Re: ---3

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.

2 Answers

Kenneth Brody

3/21/2011 5:14:00 PM

0

On 3/18/2011 6:32 PM, jameskuyper wrote:
[...]
> 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?
[...]

I've seen FORTRAN implementations that pass all parameters by reference,
including constants. And, within the called function, you could modify the
"constant", and it would remain modified. (That is, the calling function
doesn't re-initialize the "constant" before each call.)

--
Kenneth Brody

Sjouke Burry

3/21/2011 6:17:00 PM

0

Kenneth Brody wrote:
> On 3/18/2011 6:32 PM, jameskuyper wrote:
> [...]
>> 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?
> [...]
>
> I've seen FORTRAN implementations that pass all parameters by reference,
> including constants. And, within the called function, you could modify the
> "constant", and it would remain modified. (That is, the calling function
> doesn't re-initialize the "constant" before each call.)
>
That was around 1969, with fortran 2(or 4?) (pdp7, 18bit 8Kb memory).
It allowed you to prove that 1 equals 2.