Why Did This Work (Infinitely nested GOSUBs)?
Harry Stoner
Posts: 54
I just realized some code I have that seems to work great on a BS2p24 is wrong. I have a GOSUB where I meant to use a GOTO. This should result in infinite recursion. In many programming environments I would blow the stack space in a matter of seconds. Yet the program seems to function fine. Why?
Main loop of the program is structured like this:
MAIN_LOOP:
GOSUB dosomework
GOSUB dosomethingelse
GOSUB MAIN_LOOP ' should be GOTO!
Just curious. The loop executes continuously about 60 times per second. I will fix this soon.
Another question: how much time would a DEBUG statement waste if the Stamp is not connected to a serial port. e.g. is there any wait logic in the DEBUG command, or would it just clock out the data and be done with it? I also discovered some DEBUG statements in my code that I forgot to remove and just wondered how much time they are taking up/wasting (aside from instruction parsing).
Thanks.
Harry
Main loop of the program is structured like this:
MAIN_LOOP:
GOSUB dosomework
GOSUB dosomethingelse
GOSUB MAIN_LOOP ' should be GOTO!
Just curious. The loop executes continuously about 60 times per second. I will fix this soon.
Another question: how much time would a DEBUG statement waste if the Stamp is not connected to a serial port. e.g. is there any wait logic in the DEBUG command, or would it just clock out the data and be done with it? I also discovered some DEBUG statements in my code that I forgot to remove and just wondered how much time they are taking up/wasting (aside from instruction parsing).
Thanks.
Harry
Comments
The DEBUG command will execute the same no matter whether or not anything is there listening to the output.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
Your case, on the other hand, NEVER un-wraps that last gosub. So you keep 'rotating' through the return stack, but that has no negative effects.
This belongs to the collection of cool tricks you collect through painful experience.
Thanks for sharing it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
······ Bob, Ottawa
W75 54 17·· N45 18 30
·········· G16 #27