[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Arithmetic assignment side-effects

From: Linda Walsh
Subject: Re: Arithmetic assignment side-effects
Date: Sun, 04 Aug 2013 18:08:18 -0700
User-agent: Thunderbird

Chris Down wrote:
Yes, I agree, it becomes ambiguous when described in this fashion. I think the
aesthetics of x+=y vs x=x+y are important here.

From the bash manpage, it would see that += is higher precedence
than assignment, so the increment would be done first, followed
by the attempt at an assignment of 1 to 1.

(Which might be determined as 'true', = 1 in (()) expressions...
so -- only in looking at the manpage, I'd have to lean toward '1'.

(I had been leaning toward 2 since the ='s are evaled from the right, but
the += is done first according to this:

The  operators  and their precedence, associativity, and values are the
       same as in the C language.  The following list of operators is  grouped
       into  levels  of  equal-precedence operators.  The levels are listed in
       order of decreasing precedence.

       id++ id--
              variable post-increment and post-decrement
       ++id --id
              variable pre-increment and pre-decrement
       - +    unary minus and plus
       ! ~    logical and bitwise negation
       **     exponentiation
       * / %  multiplication, division, remainder
       + -    addition, subtraction
       << >>  left and right bitwise shifts
       <= >= < >
       == !=  equality and inequality
       &      bitwise AND
       ^      bitwise exclusive OR
       |      bitwise OR
       &&     logical AND
       ||     logical OR
              conditional operator
       = *= /= %= += -= <<= >>= &= ^= |=
       expr1 , expr2

reply via email to

[Prev in Thread] Current Thread [Next in Thread]