JFP has Bookmarks as well but I've just never used them. Hmmm..., have to look into them now. F5 has been so convenient (must display nearly 100 SFM's in just one screen without having to scroll. I'll have to count 'em one day)
==================================
"Everything has been figured out,
except how to live."
Jean-Paul Sartre (1905-1980)
==================================
Announcement
Collapse
No announcement yet.
Exception error on RETURN statement
Collapse
X
-
Whereas with Gosub, one has to scroll (maybe many lines), take a look, maybe edit, then have to scroll (maybe many lines) back to the Gosub.
Rod
Leave a comment:
-
-
One (intermediate) advantage of using a Sub/Function/Macro (SFM) instead of a Gosub while programing is the SFM Window/Dialog (F5 in JellyFishPro). When working on code, one can more easily F5, highlight the sfm and jump right to it. Whereas with Gosub, one has to scroll (maybe many lines), take a look, maybe edit, then have to scroll (maybe many lines) back to the Gosub.
Not disparaging Gosub (often use it myself), only pointing out a (or an in)significant drawback.
===================================
"The only difference between me
and a madman is that I'm not mad."
Salvador Dali (1904-1989)
===================================
Leave a comment:
-
-
The biggest mistake folks make with GOSUB/RETURN is "falling-through" into the subroutine, which executes the RETURN without a prior GOSUB. That's a guaranteed GPF.
Got the GPF, too.
'Twas yet anothermoment when I found it.
MCM
Leave a comment:
-
-
Yes, it's perfectly safe to EXIT a function without a RETURN to a GOSUB. PowerBASIC handles all the messy details for you. That said, I just can't bring myself to write code that way. It just has no symmetry. {smile}
The biggest mistake folks make with GOSUB/RETURN is "falling-through" into the subroutine, which executes the RETURN without a prior GOSUB. That's a guaranteed GPF.
Code:SUB abc() GOSUB Routine ' do something Routine: ' do something else... RETURN END SUB
Best regards,
Bob Zale
PowerBASIC Inc.
Leave a comment:
-
-
I would have thought so, otherwise PB would have added the error: No EXIT FUNCTION|SUB from GOSUB
PB has always handled EXIT statement be "tidying" up the stack (unless it was messed up with ASM statements)
Leave a comment:
-
-
I just took some of the medicine which I prescribed for Donald Darden and actually read the help on GOSUB, all of it, word by word. I usually skim reading matter, but since my spectacles got weaker this is not without hazard.
What it also says is:Note that ON GOSUB (and ON GOTO) have been internally optimized to produce greater run-time performance than was possible with previous versions of PowerBASIC
When I use GOSUB - in search of better performance as it happens - I follow Mr Zale's advice:Each subroutine should end with RETURN, which causes execution to resume with the statement immediately following the ON GOSUB statement.
Leave a comment:
-
-
GOSUB is VERY handy when you need time-critical code that must branch to the same routine at least once. The speed difference using GOSUB rather than setting up/releasing a stack frame (when calling a FUNCTION) in looping code is astounding. There is no point comparing GOSUB to GOTO <label>, CALL <FUNCTION>, or CALL <SUB>, as it is completely different.
MACRO is the closest you will get to GOSUB, but sometimes it's nice to keep all related code in just one procedure with two or more GOSUB branches. Of course, it can be abused (as with most branch statements, such as GOTO), but that is usually due to the programmer's inexperience. My first large BASIC program used many GOTOs/GOSUBs, but I learnt from it when it got harder to understand the code later on.Last edited by Kev Peel; 8 May 2008, 11:30 PM.
Leave a comment:
-
-
GOSUB calls share all the data and variables visible where the call is made. There is no distinction from variables and data handled by the called gosub rountine. SUBs and FUNCTIONs only share what is global or passed to/from them. Between recursive and repeated calls to a SUB or FUNCTION, static variables retain their values. Local variables are assigned space on the stack and set to zero on each call.
Speed is not everything. The added methods of handling data and isolating variables can really be used to an advantage. When developing code, SUB and FUNCTION are much easier to deal with as modules, rather than the distributed calls that you have with GOSUB and RETURN. They even help further in debugging because you have the option to step into, step over, or step out of either a SUB or FUNCTION. Not so with a GOSUB and RETURN implementation.
If you want even faster speed, then you would be arguing that MACROs are the only way to go. Every technique has its positives and negatives. Like GOTOs, GOSUB and RETURN imposes some peril and responsibility on the programmer, and it it ends up in a thread like this, I would have to say it is because the user simply did not appear to know this.
I've used GOTO, GOSUB, and similar branches many times, because I know that they have their place. The primary reason for using GOSUB is not to go fast (which it does), but because you want the embedded code to act on the variables and data that it holds in common with the calling process. That's all. Otherwise, you end up having to pass a lot of parameters back and forth to no real purpose. On the other hand, you can make the items to be shared GLOBAL in nature, meaning that they are accessible at all levels of your code. It's something of a judgement call in which way to go.
Leave a comment:
-
-
Maybe an interesting addition would be local functions/subs (i.e. visible only to the function/sub in witch they are declared), with (eventual) parameters passed on the registers.
Bye!
Leave a comment:
-
-
Originally posted by Cliff Nichols View PostDepending on the application:
I personally stay away from GOSUB on the sheer reason that for each one, its just as easy (if not easier) to create a function from the common routines, that other functions may be able to use at a future date (aka, if I write it, and realize I am duplicating the core idea in each function, with a slight twist, then I make the core idea a function, and code for "What-If" twist). ...
It's handy with some of the things I use over and over. So far the debugger's step through option has been sufficient for my needs when I encounter suspect GOSUBs.
Stan
Leave a comment:
-
-
Depending on the application:
I personally stay away from GOSUB on the sheer reason that for each one, its just as easy (if not easier) to create a function from the common routines, that other functions may be able to use at a future date (aka, if I write it, and realize I am duplicating the core idea in each function, with a slight twist, then I make the core idea a function, and code for "What-If" twist)
that and it eliminates a lot of "Hard to Find" bugs, that can not be solved by messageboxes, or logging errors, because just the messagebox, or the log being written, could allow enough time (and enough other functions) to correct the error that originally occurred and making it harder to find.
Leave a comment:
-
-
Originally posted by Donald Darden View PostAnyone using GOSUB and RETURN rather than a SUB, EXIT SUB, END SUB tends to suggest someone not yet well versed in all the power and options presented by PowerBasic.
For time critical or high-performance code, using a GOSUB to perform a repetitive task is almost always faster then performing a call to a Sub or Function, since there is no overhead in setting up a stack frame for a GOSUB
Leave a comment:
-
-
I see no update on this post. I seriously doubt that it casts doubt on how PowerBasic compilers handle GOSUB and RETURN operations. These compilers have been tested time and time again, and we all know how stable and reliable they are.
Anyone using GOSUB and RETURN rather than a SUB, EXIT SUB, END SUB tends to suggest someone not yet well versed in all the power and options presented by PowerBasic. That PowerBasic supports GOSUB and RETURN still is a testament to their commitment to let programmers program as they choose. But the structure and automatic error checking inherent in using formal procedures like SUB and FUNCTION make them the preferred method of coding redundant processes. The risk with GOSUB and RETURN is that these may not mate up correctly in spagetti code, and this can be a major problem to isolate and resolve.
Any call structure, whether GOSUB, RETURN, CALL, or EXIT (sub or function) effect the contents of the stack. Further, for SUBs and FUNCTIONs, passed parameters and local variables also are assigned space on the stack. GOSUB and RETURN are going to modify the stack, or stack pointer, any time they are used. And when the two do not balance each other out, the stack will be corrupted. Which is why we don't use them much any more. It puts too much responsibility on the programmer to get the code esactly right, and not jump to false conclusions when it blows up.
Leave a comment:
-
-
the very act of simplifying your code to make an example of the problem to post in this forum will probably lead you quickly to a resolution
Other symptoms include posting messages which incorporate theicon.
Leave a comment:
-
-
Originally posted by Michael Mattias View PostYour best bet at this point is to post the code
Leave a comment:
-
-
BTW, see the CALLSTK function if you are convinced the problem is with your stack.
I'm not sure that handles GOSUB/RETURN, but you could just restructure
Code:GOSUB Foo ... foo: code code code RETURN
Code:CALL Foo (variables needed by subroutine as parameters) ... ... FUNCTION Foo (variables needed by subroutine as parameters) code code code END FUNCTION
Leave a comment:
-
-
Because it happens on the return I'm guessing the stack is being corrupted somewhere between the beginning of the gosubbed code and the return point.
Yes, it is possible the stack is being corrupted. It's also possible it's not.
It's possible the corruption is in fact occuring between the GOSUB and the RETURN. It's also possible the corruption is occurring elsewhere... somewhere you think it just not possible to occur.
Your best bet at this point is to post the code from the GOSUB'd label through the RETURN and see if a fresh set of eyes can spot something. But don't be surprised if that only leads to requests to post additional code, because it is by no means a certainty the corruption is occurring in this particular snippet.
MCM
Leave a comment:
-
-
Thanks for the reply.
I am getting an %EXCEPTION_ACCESS_VIOLATION trying to read data.
Because it happens on the return I'm guessing the stack is being corrupted somewhere between the beginning of the gosubbed code and the return point. I am just wondering if it is possible to monitor the return address to see when it changes.
I tried the error checking from the FAQ but didn't get any error logged.
Leave a comment:
-
Leave a comment: