Coverting GOSUB to GOTO?
#9
(12-30-2022, 06:38 PM)James D Jarvis Wrote: Does the compiler convert simple GOSUB commands into GOTO commands?   This little bit of code refuses to die, I thought there would be a stack overflow but nope, not while I was running it.  just keeps wrapping around to -32K and counting back up until it wraps aroundound again and again.

Code: (Select All)
10 Rem bad code...bad
t1 = Timer
20 a% = 0
30 a% = a% + 1
40 Print a%, Timer - t1
50 GoSub 30

Open task manager.  Run the program.  Watch the memory usage go endlessly upwards.

The climb is slow, but steady, on my machine.  The gosub keeps building return points that it never comes back to, and as it runs, the memory usage goes up, up, and up.   I imagine it'd hit the upper memory limits of a 32-bit OS within about 10 minutes or so.  On a 64-bit OS, I suppose eventually it'd use up available memory, then swap over to running in a swapfile...  until eventually it used up all the space on your hard drive and memory both.   

In either case, I don't think it's the type of results one would want in their code.   If you need a GOTO, use a GOTO, not a GOSUB.  Wink
Reply


Messages In This Thread
Coverting GOSUB to GOTO? - by James D Jarvis - 12-30-2022, 06:38 PM
RE: Coverting GOSUB to GOTO? - by SpriggsySpriggs - 12-30-2022, 07:20 PM
RE: Coverting GOSUB to GOTO? - by James D Jarvis - 12-30-2022, 07:47 PM
RE: Coverting GOSUB to GOTO? - by bplus - 12-30-2022, 07:23 PM
RE: Coverting GOSUB to GOTO? - by James D Jarvis - 12-30-2022, 07:44 PM
RE: Coverting GOSUB to GOTO? - by bplus - 12-30-2022, 08:33 PM
RE: Coverting GOSUB to GOTO? - by bplus - 12-30-2022, 07:56 PM
RE: Coverting GOSUB to GOTO? - by SpriggsySpriggs - 12-30-2022, 08:14 PM
RE: Coverting GOSUB to GOTO? - by SMcNeill - 12-30-2022, 11:29 PM
RE: Coverting GOSUB to GOTO? - by SMcNeill - 12-30-2022, 11:41 PM
RE: Coverting GOSUB to GOTO? - by bplus - 12-31-2022, 06:26 PM
RE: Coverting GOSUB to GOTO? - by SMcNeill - 12-31-2022, 07:19 PM
RE: Coverting GOSUB to GOTO? - by James D Jarvis - 12-31-2022, 12:41 AM
RE: Coverting GOSUB to GOTO? - by mnrvovrfc - 12-31-2022, 02:18 AM
RE: Coverting GOSUB to GOTO? - by James D Jarvis - 12-31-2022, 07:13 PM
RE: Coverting GOSUB to GOTO? - by euklides - 12-31-2022, 12:35 PM



Users browsing this thread: 3 Guest(s)