× 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: RE: Variable parameter type
  • From: Bob Crothers <bob@xxxxxxxxxxxxxx>
  • Date: Tue, 17 Nov 1998 17:29:55 -0000
  • Organization: Cornerstone Communications, LLC

David,

On re-reading the original post, he says "The type of the value 
returned depends on the parameters passed".

It sounds like the type of the parms passed do not change, only what 
is returned.

You could pass a data structure (or some such) back with a flag to 
indicate what kind of value is in the DS and let the calling program 
sort it out (like Eric suggested).  But I don't really like this as it 
seems cumbersome.

If the calling program knows what to expect back, then I'd probably go 
with separate procedures. One for each type.  Especially if the base 
logic can be put into a helper function that actually does most of the 
work.

If the calling program does not know what to expect, then Eric's 
suggestion is probably the one to use.

With overloading (as done by C++, I can't speak for other OO 
languages), the parameter types must differ.  And the decision is made 
at compile time.  So if the caller does not know what to expect back, 
even in C++, you would just about have to pass something to indicate 
what it is.

But yes, overloading in C++ is great. And might be even better in a 
"pure OO language".  And yes, like many things, overloading in C++ 
works the same as in Java.

Not sure if templates would help.  My knowledge of them is limited and 
has so far been restricted to using those that the compiler vendor has 
provided.  I've never created my own.  But as I understand them, it is 
all done at compile time.  But then, I could be missing your point 
also.

Bob

-----Original Message-----
From:   David Morris [SMTP:dmorris@plumcreek.com]
Sent:   Tuesday, November 17, 1998 3:33 PM
To:     MIDRANGE-L@midrange.com
Subject:        Re: RE: Variable parameter type

Bob,

Passing pointers is obviously fraught with danger.  That is the only 
alternative
when you have a long list of variable type parameters.  We are only 
talking
about 1 parameter with three possible types.  This breaks down when 
there
several parameters with a bunch of types.  This is why RPG should 
really
support variable types.  Without this support RPG programmers are 
forced
to manage storage, which is not the best use of our time.

Speaking as a RPG guy with almost no C++ experience, I would think 
that
overloading is one method that could be used to support this in RPG. 
 RPG
could also benefit from parameterized type support.  This would be 
like to a
template in C++.

David Morris

>>> Bob Crothers <bob@cstoneindy.com> 11/17 3:36 AM >>>
Speaking as a C++ guy with a LOT of experience in pointers, BEWARE OF
THIS APPROACH!

Passing back a generic pointer (Don't know if you can even do this in
RPG) and letting the caller decide what it is a pointer to, is very
dangerous.  This is the sort of thing that gives pointers a bad name.

If you pass back a pointer  to a character string, but the app decides 
that you should be passing a pointer to an integer, then nasty things
will happen.

I highly recommend that you do not do this.  Instead, declare 3
different functions.

In C++, there is a cool thing called "overloading" that is meant for
this sort of thing.  Perhaps someday, RPG will be able to do this.

Say you have a function "ConvertMyThing" that must handle 3 different
types of parms.  You would declare them as:

int ConvertMyThing (int myNumber);

string ConvertMyThing (string myString);

double ConvertMyThing (double myDouble);

In your code, you would always just call ConvertMyThing ().  And the
compiler picks the correct function to call based on the parameter
types you are using.  And of course, if the type changes, the correct
function is always called.

BTW, like anything else, there can be pitfalls in overloading also.

Regards,
Bob Crothers
Cornerstone Communications, LLC
www.faxserver401.com


-----Original Message-----
From:   Denis Robitaille [SMTP:DRobitaille@cascades.com]
Sent:   Tuesday, November 17, 1998 9:05 AM
To:     MIDRANGE-L@midrange.com
Subject:        Variable parameter type

Hello all, on a project i am working on, i need to write a program or
procedure that will return a value. The type of the value returned
depends on the parameters passed. It can be a number, a caracter
string or a booleean. I would like to avoied declaring 3 parameters
for each possible type of values. I tought that i may use a pointer,
but i am not sure.

Any suggestions?

Denis Robitaille
Cascades inc.
Tel: 819-363-5187
DRobitaille@cascades.com

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

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