|Side effects in expressions firstname.lastname@example.org (Tzvetan Mikov) (1999-08-18)|
|Re: Side effects in expressions email@example.com (1999-08-18)|
|Re: Side effects in expressions firstname.lastname@example.org (1999-08-21)|
|From:||email@example.com (John McEnerney)|
|Date:||18 Aug 1999 11:29:20 -0400|
"Tzvetan Mikov" <firstname.lastname@example.org> wrote:
> So, this expression is calculated correctly and we can even easily apply a
> very simple common sub-expression elimination. What happens however if we
> have sub-expressions with side effects? Examine this C code:
> int * p = ...;
> x = *(p = p + 1) + *(p = p + 1);
This is probably not a good example, as the behavior of this
expression is undefined (in ANSI C) because the compiler is free to
evaluate the assignments to 'p' anywhere between the previous ';' and
the subsequent one.
But I think that the usual understanding is that during translation
from abstract syntax trees to IL, side-effecting expressions are
hoisted as if they were independent statements. This is also true of
flow-of-control operators like && and || and ?:.
So all side-effects occur as the "root" of the expressions that
contain them. I suspect that the return values of function calls are
assigned to "variable" temporaries rather than expression temporaries.
I like the Morgan book a lot, but although it seems to be a modern
version of "The Design of an Optimizing Compiler", the difference is
that Wulf et al were describing a compiler that actually
existed. Morgan is describing a proposed design, some parts of which
are taken from compilers that exist, and some of which haven't been
implemented in the proposed form. Still, he's very complete.
John McEnerney (email@example.com)
Return to the
Search the comp.compilers archives again.