On 20/02/07, August Karlstrom <fus...@co...> wrote:
>
> Hi,
>
> With OO2C 2.1.11 the following module compiles and prints "0".
>
> MODULE Test;
>
> IMPORT Out;
>
> PROCEDURE Q(p: PROCEDURE); BEGIN p END Q;
>
> PROCEDURE P;
> VAR n: LONGINT;
> PROCEDURE Inner; BEGIN INC(n) END Inner;
> BEGIN
> n := 0;
> Q(Inner);
> Out.Int(n, 0); Out.Ln
> END P;
>
> BEGIN
> P
> END Test.
>
> Standard Oberon-2 does not support closures but even if it did I think
> the result should be "1".
Correct on both counts. gcc does some tricky things to get local
functions
to work via pointers, so the above code does not crash outright.
And the result should be "1".
Comments?
The intermediate code representation is rather optimistic about the
possbility of
changes to local variables, and changes via a trampoline external to the
procedure itself are not factored in. The assumption is that Q, which is
not
local to P and also does not get a pointer to "n", cannot possibly change
the
value of "n". This is wrong in this case.
One fix would be to assume that any call to any procedure might change any
local
variable if the address of a nested procedure is taken somewhere.
-- mva
|