Re: [ast-users] Arithmetic assignment side-effects

2013-08-06 Thread Janis Papanagnou
  
  Go strictly from left to right.
 
 How do you assign something that hasn't been evaluated yet? Evaluating the 
 expression on the RHS is an absolute prerequisite to evaluating the 
 assignment 
 itself. (x += x) = 1 is nonsense. It evaluates to 0 = 1.

It makes sense, depending on the language. With LVALUE=RVALUE and
LVALUE+=LVALUE, where the result is an LVALUE, consider it evaluated as

(ref(x) = deref(x)+deref(x)) = 1

(Try your expression above in C++, for example. It works as expected.)

Nonetheless right to left parsing seems the only sensible semantics in
case of = and op= assignments.

Janis

 
[...]
 
 I've also already proven that at least in ksh it goes right to left, because 
 if you define a setter property to trigger a side-effect for each variable, 
 the RHS fires before the LHS of the +=.
 
 There's just no amount of mind-bending I can think of that could make 
 evaluating the += first produce anything other than an error.
 -- 
 Dan Douglas
 ___
 ast-users mailing list
 ast-users@lists.research.att.com
 http://lists.research.att.com/mailman/listinfo/ast-users
  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Arithmetic assignment side-effects

2013-08-06 Thread Janis Papanagnou
Oops. Should have been...





  (x += x) = 1 is nonsense. It evaluates to 0 = 1.

 It makes sense, depending on the language. With LVALUE=RVALUE and
 LVALUE+=LVALUE, where the result is an LVALUE, consider it evaluated as

LVALUE+=RVALUE

 (ref(x) = deref(x)+deref(x)) = 1

 (Try your expression above in C++, for example. It works as expected.)

 Nonetheless right to left parsing seems the only sensible semantics in
 case of = and op= assignments.
 
 Janis

  ___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Arithmetic assignment side-effects

2013-08-05 Thread Anders Johansson
On 08/04/2013 12:41 AM, Dan Douglas wrote:
 On Sunday, August 04, 2013 12:30:48 AM Roland Mainz wrote:
 On Sun, Aug 4, 2013 at 12:04 AM, Dan Douglas orm...@gmail.com wrote:
 Is it specified what the value of x should be after this expression?

 x=0; : $((x+=x=1))

 Bash, ksh93, mksh, posh say 1. zsh, dash, busybox say 2. Clang and gcc 
 both throw warnings about it, but both plus icc agree on 2.
 Just curious: Is that x86-specific or is the result always the same on
 other architectures, too ? Maybe there is something in ISO C1X/C99
 which actually defines or recommends a specific compiler behaviour.

It is expressly forbidden by C99 (6.5.2:


 Between the previous and next sequence point an object shall have its stored 
 value modified at most once by the evaluation of an expression. Furthermore, 
 the prior value shall be read only to determine the value to be stored.

As such, the expression in question here (x+=x=1) is undefined
 Anders


___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users


Re: [ast-users] Arithmetic assignment side-effects

2013-08-05 Thread Roland Mainz
On Mon, Aug 5, 2013 at 9:01 AM, Anders Johansson ajohans...@suse.com wrote:
 On 08/04/2013 12:41 AM, Dan Douglas wrote:
 On Sunday, August 04, 2013 12:30:48 AM Roland Mainz wrote:
 On Sun, Aug 4, 2013 at 12:04 AM, Dan Douglas orm...@gmail.com wrote:
 Is it specified what the value of x should be after this expression?

 x=0; : $((x+=x=1))

 Bash, ksh93, mksh, posh say 1. zsh, dash, busybox say 2. Clang and gcc
 both throw warnings about it, but both plus icc agree on 2.
 Just curious: Is that x86-specific or is the result always the same on
 other architectures, too ? Maybe there is something in ISO C1X/C99
 which actually defines or recommends a specific compiler behaviour.

 It is expressly forbidden by C99 (6.5.2:


 Between the previous and next sequence point an object shall have its 
 stored value modified at most once by the evaluation of an expression. 
 Furthermore, the prior value shall be read only to determine the value to 
 be stored.

 As such, the expression in question here (x+=x=1) is undefined

Thanks for the answer... :-)



Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) roland.ma...@nrubsig.org
  \__\/\/__/  MPEG specialist, CJAVASunUnix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)
___
ast-users mailing list
ast-users@lists.research.att.com
http://lists.research.att.com/mailman/listinfo/ast-users