Hi,
my dodgy memory seems to suggest that this has been discussed before; but I cannot find any related threads just now. I've just spent some time trying to figure out the cause of a crash in a complex bit of code and it turned out to be the use of a Goto statement to cross from one Select/EndSelect construct to another within a procedure. I quite often jump from one Case clause to another within the same Select construct without any problems, but jumping between Selects appears to be a no go area within a procedure.
The same is true (within a procedure) if using Goto within a Case clause to jump outside of the Select/EndSelect code as can be seen with this code (stack corruption) :
Code: Select all
Procedure test(a)
testVar = 100
Select a
Case 1
Goto L1
EndSelect
L1:
Debug "testVar (should = 100) equals " + Str(testVar) ;Reports incorrect value.
End ;Comment this to get a crash!
EndProcedure
test(1)
Now, looking at the ASM generated by the PB compiler, it is obvious how the above leads to stack corruption since the stack is used as part of the Select statement itself, but what I am asking is whether what I am doing is really unreasonable? I guess I am really wondering why the stack is being used internally in the processing of a Select statement? Would it perhaps not be better to use a register instead?
At the very least, a note in the help manual to the effect that we should avoid using Goto to jump between Select / EndSelect routines etc. would be useful for those spaghetti merchants like myself!
