Method for Clearing GOSUB...RETURN Subroutine Stack in BASIC (44306)
This article was previously published under Q44306
SUMMARY
When a program jumps out of a GOSUB subroutine without executing a
RETURN statement, the return address is left on the stack. If the
program jumps out multiple times, an "Out of Stack Space" or "Out of
Memory" error eventually occurs. You must make your program execute an
equal number of GOSUB and RETURN statements to avoid this error.
The program below demonstrates a method for clearing the subroutine
stack when a program executes more GOSUB statements than RETURN
statements. Generally, a program should get out of a GOSUB subroutine
with a RETURN statement, but when that is not feasible, the method
below may be used.
This information applies to Microsoft QuickBASIC Versions 1.00, 1.01,
2.00, 2.01, 3.00, 4.00, 4.00b, and 4.50 for MS-DOS; Microsoft GW-BASIC
Interpreter Versions 3.20, 3.22, and 3.23 for MS-DOS; Microsoft BASIC
Interpreter Version 5.28 for MS-DOS; Microsoft BASIC Compiler Versions
5.35 and 5.36 for MS-DOS; Microsoft BASIC Compiler Versions 6.00 and
6.00b for MS-DOS and MS OS/2; and Microsoft BASIC PDS Version 7.00 for
MS-DOS and MS OS/2.
Modification Type: |
Minor |
Last Reviewed: |
1/9/2003 |
Keywords: |
KB44306 |
|