12-30-2022, 11:29 PM
(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.