bug-bash
[Top][All Lists]
Advanced

[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: Mon, 5 Aug 2013 22:54:30 -0400

On Sun, Aug 4, 2013 at 9:08 PM, Linda Walsh <address@hidden> wrote:

>
>
> 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
>        <= >= < >
>               comparison
>        == !=  equality and inequality
>        &      bitwise AND
>        ^      bitwise exclusive OR
>        |      bitwise OR
>        &&     logical AND
>        ||     logical OR
>        expr?expr:expr
>               conditional operator
>        = *= /= %= += -= <<= >>= &= ^= |=
>               assignment
>        expr1 , expr2
>               comma
>
>
Where do you see that? They're all equal in precedence:

"The following list of operators is grouped into levels of equal-precedence
operators."

 = *= /= %= += -= <<= >>= &= ^= |=
              assignment


reply via email to

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