|
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 +---
As an Amazon Associate we earn from qualifying purchases.
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.