[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: undefined compound chaining behavior
From: |
Hossein Sajjadi |
Subject: |
Re: undefined compound chaining behavior |
Date: |
Fri, 13 Jun 2014 13:30:22 +0330 |
>
> Ahh, I see, sorry, could you give me the link again to the Octave C++
> source code where this undefined behaviour statement occurs?
>
> Richard
The code is very complicated and very long.
There is no need to search the code to find where the undefined behavior occurs.
>From behavior of octave we can conclude about structure behind the += operator.
It is actually the same operator as c++ or is a function such as :
double add_eq (double& lhs ,double rhs)
{
lhs=lhs+rhs;
return lhs;
}
the function gets two arguments:
the first is a reference to a scalar variable(lvalue) and the other is
a rvalue or is an expression.
(Note: an expression in octave always results rvalue even assingment operator)
why the first is a reference to a scalar variable? because we cannot
bring an expression in lhs such as
octave> (a=1)+=2
why the first is a reference ( or a pointer to a variable) and is not a value?
:Because the function has side effect.The function always returns
rvalue (a function is an expression) and its side effect is to update
value of the first argument;
why the function has side effect?
:Because when chaining the compound assignment the value of the first
argument is in place updated.
octave> a=1;a+=(a+=4)
so in the current version of octave when first the rhs is evaluated,
"a",as an argument to a function, is updated, but result of the
expression (a+=1) is always an rvalue, so "a" must be updated in the
body of the function.
result of the parentheses is 5 and its side effect is updating the
value of "a" to be 5 .
so 5+5= 10
If we assume that the += operator is the so mentioned function, again
undefined behavior takes place.
Because in c++ order of evaluation of function's arguments unsequenced.
====
-Hossein
- Re: undefined compound chaining behavior, (continued)
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/12
- Re: undefined compound chaining behavior, Jordi GutiƩrrez Hermoso, 2014/06/12
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/12
- Re: undefined compound chaining behavior, Jordi GutiƩrrez Hermoso, 2014/06/12
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Richard Crozier, 2014/06/13
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Richard Crozier, 2014/06/13
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Richard Crozier, 2014/06/13
- Re: undefined compound chaining behavior,
Hossein Sajjadi <=
- Re: undefined compound chaining behavior, Richard Crozier, 2014/06/13
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Ben Abbott, 2014/06/13
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Ben Abbott, 2014/06/13
- Re: undefined compound chaining behavior, Hossein Sajjadi, 2014/06/13
- Re: undefined compound chaining behavior, Benjamin Abbott, 2014/06/13
- Re: undefined compound chaining behavior, John W. Eaton, 2014/06/13
- Re: undefined compound chaining behavior, Mike Miller, 2014/06/13
- Re: undefined compound chaining behavior, John W. Eaton, 2014/06/13