Qbasicnews.com
December 11, 2019, 06:09:06 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: gosub stack overflow  (Read 1228 times)
xteraco
Ancient QBer
****
Posts: 450



WWW
« on: February 20, 2005, 04:55:16 PM »

got a different question. .ok here goes.. i know if you use gosub too much it can cause a stack overflow... but what if i use subroutines... and dont actually use gosub??? or when i use the subroutine is it the same as using gosub.. ..  grrrraaaahhh!!! my head hurts
Logged

url=http://www.random-seed.net][/url]
Z!re
*/-\*
*****
Posts: 4599


« Reply #1 on: February 20, 2005, 05:07:20 PM »

You only cause a stack overflow if you use GOSUB without using RETURN

If you use a SUB that calls itself without ending, you will get the same effect, namely STACK OVERFLOW.

examples, causes overflow:
GOSUB:
Code:
1 Do
Gosub 1
Loop

SUB/FUNCTION:
Code:
declare sub foo

foo

sub foo
 foo
End sub


GOSUB puts the return adress (the current position in the program) on the stack, so you can return to where you last used GOSUB by using RETURN.

When you call a SUB/FUNCTION the same thing is done, so that when the SUB/FUNCTION is done it jumps to the instruction immediately after the sub jump.
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!