Page 1 of 1

Local?

Posted: Mon Apr 12, 2010 10:26 pm
by Kjell
:!:

Came across some strange behavior .. and realized / found out that locally defined variable are currently actually global / static ( unlike what I thought before ). While the script editor does prevent you from accessing variables that are defined in another scope, you can access the variable from another script ( so it hasn't been freed + re-initialized ).

For example in the first ZExpression ..

Code: Select all

for(int A=0; A<64; ++A){}
.. and in the second ..

Code: Select all

int A;
Variable = A;
.. results in the Variable being assigned 64.

Feature or bug? :wink:

K

Posted: Tue Apr 13, 2010 1:53 pm
by VilleK
Variables are not initialized by ZGE before they are used so their initial value is undefined.

In your example it is not that both variables are named "A" that gives this behavior, instead it is that it is the first local variable in each expression. Local variables are defined on the ZGE expression evaluation stack which is not cleared between expressions. If the first expression has "int a,b" and the second "int b,a" then the variables may keep their value between expressions (swapped so a=b, b=a), but lets just say it is not something to rely on :).

Posted: Tue Apr 13, 2010 2:07 pm
by Kjell
:)

Ah I see, that's good to know ( shouldn't use this "feature" then ) ~ Thanks for clearing that up!

K