× 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.


  • Subject: Re: Prototype in RPG/ILE
  • From: Jim Langston <jlangston@xxxxxxxxxxxxxxxx>
  • Date: Fri, 11 Feb 2000 15:45:56 -0800
  • Organization: Conex Global Logistics Services, Inc.

Question is: What is the purpose of Prototype and it's relationship to
the procedure.

I can give you one of 2 answers, one technical and one the reason.  First,
the reason.

Answer: The compiler requires it to compile.

Now the technical answer (behind the scenes)

Answer: When the compile goes through a program and it sees an external
call, it has to know how to put everything to be passed in order.  It also has
to ensure that all required parameters are there.  Since the Subprocedure
is usually not reached in the program before the call is found, or may not
even be found in that source at all, the compiler needs a way to have this
information.  Hence, the prototype (almost all languages use it in one way
or another).

The prototype tells the compiler that there is a certain called called such
and such that is expecting these types of parameters and returns this type
of parameter.  Now, when the compile finds the call, it has all the information
it needs to build the statements to call the routine.

Take a simple call to atol (Ascii to Long).

 D atol            PR            10I 0 ExtProc('atol')
 D                                 *   Value Options(*String)

The first line gives 4 pieces of information to the compiler.
"atol" - What I am calling this in my program, how I am going to call it.
      In this case atol
"10I" - The returning parameter, in this case 10 digit integer (Zoned)
"ExtProc" - This is an external procedure, not found in this source file.
"'atol'" - This is the name of the procedure in some other file I am going
     to link to.

The second line gives the compiler one piece of information, in this case
the one parameter I need to pass to the Subprocedure.
"*" - It is a pointer I am passing (location of a variable)
"Value" - I am passing the parameter by value, that is, a copy of it, not
     the real thing
"Options(*String)" - I'm going to be passing a pointer to a string.

Now the compiler has all the information it needs to compile without
having a copy of the subprocedure it is going to link to.

Regards,

Jim Langston

Bruce Collins wrote:

> I am trying to learn to use Subprocedures instead of Subroutines in RPG/ILE.
> I am having a problem understanding What the purpose of the Prototype and
> its relationship to the procudure. Could someone shed some light on this
> please.

+---
| 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 ...

Follow-Ups:
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.