Active Forums => QB64 Discussion => Topic started by: RhoSigma on December 09, 2018, 12:05:58 pm
Title: Bug or design? - GOSUB related
Post by: RhoSigma on December 09, 2018, 12:05:58 pm
Just stumbled over this one, i know the shown concept is certainly not a nice programming style, but nevertheless i think a smart language should be able to handle it gracefully.
Title: Re: Bug or design? - GOSUB related
Post by: SMcNeill on December 09, 2018, 12:17:17 pm
Personally, I’m of the opinion that QB64 subs are slow enough already. Do we really need to add more overhead to them as well, to increase their delay?
SUB test (x) GOSUB test_x IF x THEN EXIT SUB ‘exit condition after return clears gosub stack EXIT SUB
test_x: IF x THEN RETURN RETURN END SUB
BASIC has always had issues with GOSUBS and exiting them without using RETURN. Honestly, I’d suggest to just make and call another SUB instead.
Title: Re: Bug or design? - GOSUB related
Post by: FellippeHeitor on December 09, 2018, 12:20:54 pm
It all resembles malpractice after all. One should be aware of their stack if they choose to use GOSUB.
CLEAR is also doing its job as expected here, clearing it all as well as the stack.
Title: Re: Bug or design? - EXIT SUB/FUNC in local GOSUB routines
Post by: Pete on December 09, 2018, 12:22:26 pm
In recall in QBasic this type of programming practice (Exiting a gosub without a return) would likely cause a stack space overflow error. Using GOTO statements in GOSUB statements were usually found to be the main culprit. Memory was very limited then in regards to what it is in QB64. I actually don't know if EXIT SUB in QB64 will return the stack or not. In Atari, POP was used if you wanted to exit a gosub without completing a return. Using POP unloaded the GOSUB call from the memory stack.
Ah three other posts while I was writing this, well..
In regard to CLEAR, I believe QBasic had some restrictions on where the CLEAR statement could and could not be placed. CLEAR and RUN are both a bit buggy in QB64.