octave-maintainers
[Top][All Lists]
Advanced

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

Re: undefined compound chaining behavior


From: Jordi Gutiérrez Hermoso
Subject: Re: undefined compound chaining behavior
Date: Thu, 12 Jun 2014 14:32:11 -0400

On Thu, 2014-06-12 at 19:49 +0330, Hossein Sajjadi wrote:
> >
> > Jordi's point is that just because you type a+=a+=4 at the Octave
> > prompt, does not mean this expression is what is ever evaluated in C++
> > code. Octave does not write a little C++ file containing the a+=a+=4
> > expression and then compile and run it after all.
> >
> > The expression is broken down by the interpreter code and evaluated in
> > whatever way the interpreter was written to do it.
> 
> As I say in previous post, it is sufficient to prove that the operator
> in both languages are the same.

No, of course it is not sufficient. Suppose, for a moment, that the
Octave interpreter written in bison transformed the Octave expression,

    x += x += y

into the following C++ expressions:

   tmp = x += y;
   x += y;

This is not too far from the truth of how the Octave interpreter
transforms the Octave statement into C++.

Then even though Octave's operator += is transformed into C++'s
operator +=, there is no UB. In order to incur UB in C++ in this case,
you *need* to make the compiler evaluate an expression more or less
identical to the original Octave expression, not a transformation of
it.

But if the compiler were evaluating such an expression, it would warn
(well, at least some compilers would warn), but I have not heard any
reports of such a warning, therefore etc.

- Jordi G. H.





reply via email to

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