[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: chaining compound assignment results in undefined behavior
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: chaining compound assignment results in undefined behavior |
Date: |
Fri, 06 Jun 2014 12:33:15 -0400 |
On Fri, 2014-06-06 at 17:20 +0330, Hossein Sajjadi wrote:
> There is a problem with chaining compound assignment.
> For example the expression a=1;a+=a+=4 will result 10.
> I think such a behavior is borrowed from C language but this behavior
> is known as "undefined behavior".
Yes, but this is not undefined behaviour in Octave. "Undefined
behaviour" is a specific term defined by the C and C++ standards.
There is no Matlab or Octave standard, so there is no definition of
"undefined behaviour" either.
> This issue have been resolven in Java.
I don't think there is any particular reason to do whatever Java does
here. Octave's behaviour here seems to be another sensible thing to
do. Normally = is right-associative, so I see no reason for += to be
left-associative.
- Jordi G. H.