[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arithmetic assignment side-effects
From: |
DJ Mills |
Subject: |
Re: Arithmetic assignment side-effects |
Date: |
Tue, 6 Aug 2013 05:31:42 -0400 |
On Tue, Aug 6, 2013 at 3:20 AM, Andreas Schwab <address@hidden>wrote:
> DJ Mills <address@hidden> writes:
>
> > I still don't see that;
>
> Go strictly from left to right.
>
>
It doesn't make any kind of logical sense to do so. Yes, then the "(x =
1)" would be evaluated
last, but how do you evaluate the entire statement, for the first "x = "?
You can say "go
left to right", but if you think about it. that's not really possible.
Unless you can explain it to me...
> gcc agrees with me.
>
> No, it doesn't.
> $ cat cascade.c
> #include <stdio.h>
>
> int main(void) {
> int x;
>
> x = 0;
> printf("\nx += x = 1\n%d\n", x += x = 1);
>
> x = 0;
> printf("\nx = x + (x = 1)\n%d\n", x = x + (x = 1));
>
> return 0;
> }
>
> $ gcc -Wall -o cascade cascade.c
> cascade.c: In function 'main':
> cascade.c:7:36: warning: operation on 'x' may be undefined
> [-Wsequence-point]
> cascade.c:10:37: warning: operation on 'x' may be undefined
> [-Wsequence-point]
>
> $ ./cascade
> x += x = 1
> 2
>
> x = x + (x = 1)
> 2
>
> $ gcc -version | head -n 1
> gcc (GCC) 4.7.2
>
>
>
>>
>> Parens have no effect at all.
>>
>> It won't even compile without them, I get:
> cascade.c:13:43: error: lvalue required as left operand of assignment
Line 13 in that case being:
printf("\nx = x + x = 1\n%d\n", x = x + x = 1);
That makes sense to me (getting an error thrown, I mean) .
- Re: Arithmetic assignment side-effects, (continued)
- Re: Arithmetic assignment side-effects, Linda Walsh, 2013/08/05
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/05
- Re: Arithmetic assignment side-effects, DJ Mills, 2013/08/05
- Re: Arithmetic assignment side-effects, DJ Mills, 2013/08/05
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/06
- Re: Arithmetic assignment side-effects, Dan Douglas, 2013/08/06
- Re: Arithmetic assignment side-effects, Andreas Schwab, 2013/08/06
- RE: [ast-users] Arithmetic assignment side-effects, Janis Papanagnou, 2013/08/06
- Re: [ast-users] Arithmetic assignment side-effects, Chet Ramey, 2013/08/06
- Re: [ast-users] Arithmetic assignment side-effects, Chet Ramey, 2013/08/06
- Re: Arithmetic assignment side-effects,
DJ Mills <=
- Re: Arithmetic assignment side-effects, Chet Ramey, 2013/08/06