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

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.