× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Colin,

>>All right, it's two GOTOS 

>What?

He's closer to being right than you may think.

In most languages, when you call a subroutine it "pushes" the current
instruction pointer onto a "stack" then branches to the start address
of the subroutine.  To return, it "pops" the "stack" to retrieve the
address from whence it came.  The "stack" is variable in size (albeit
with a finite limit), and grows larger as you nest to deeper levels.
In fact, you can even recursively call the same subroutine and as long
as there is some mechanism to stop the recursion before you run out of
stack space you will eventually pop your way back to where you started
without any problems.

However, that is not how RPG handles subroutines (at least prior to
ILE).  In RPG, it really is more like two GOTOs.  Conceptually, it is
like it changes the ENDSR to a GOTO (EXSR + 1 line), then does a GOTO
BEGSR.  No stack operations are involved.  There can only be one
return point associated with a given ENDSR at any given time.

This explains some quirks of RPG subroutines not common in most
languages, such as:

 - You can't recursively call a subroutine.  The compiler will catch
directly trying to call itself.  But it won't catch indirect calls.
The manual just gives the proverbial warning of "Indirect calls to
itself through another subroutine should not be performed, because
unpredictable results will occur."   Actually, the results are quite
predictable, but you wouldn't want to go there.

 - RPG actually lets you use GOTO to branch out of a subroutine and
back to a tag in detail or total calcs without the need to ever reach
the ENDSR statement.  In most languages, this would cause the stack to
become unbalanced but not in good 'ol RPG.  If you really want to see
some spagetti code, try adding several conditional GOTOs in a
subroutine, all branching to various locations *outside* the
subroutine!  

In fact, someone could probably use this "feature" of RPG to write
some code for Roger to demonstrate just how bad unstructured RPG can
get and still work.  Or to make the world's worst program that lists
itself.  But you'd have to use real RPG to do it, and that would break
the rules of the contest...

Doug
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.