Declaring variables mid-function changes results

BlitzMax Forums/BlitzMax Programming/Declaring variables mid-function changes results

you can not declare x twice unless its in different scopes.
So if you define x at the beginning of the function it will remain defined till its end.

And yes it optimizes things as each local will be held in cache, so if the local can be removed this means less data to keep in sync with the RAM and registers.

And yes you would not use local within a loop, that actually would be counterproductive.

But if you have if <loop> endif, you would for example declare the local within the if.
That ensures that the variable does not get generated when the if is never met -> no allocation for something not used at all, unlike it would happen otherwise.

Arrays, as all objects, are references -> ints as well.
And for numerics local is a whole different thing as they never get GC cleaned, they are no objects at all.

The whole thing is quite complex and powerfull but you can struggle quite easily as well.
Don't ask me on what strict has an influence at whole, I know for sure that it is scopes and therefor the whole GC process and its known that not using it can speed up the whole performance by 2-5 times if used correctly to enforce register / level 1 cache usage where usefull.