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



RPG doesn't have typed pointers.
If you decide to manage passing the correct data types yourself,
you're back in the bad old days of CALL + PARM, where the compiler
oculd not do any type checking.

Yes, you're right. RPG doesn't have typed pointers.

Using keyword value to pass pointers "by value" is not compatbile with C.
And no type checking, which is a real downside. Also, with "const" it's
possible to use an expression in the caller, which is not possible with a
pointer type.

But i prefer to use "value" instead "const". Because it's more "safe".
Being able to change the parameter values inside the called procedure
without the compiler checking against it is a nuisance but has no outside
effect.

With const we have type checking, but ALWAYS using const for EVERY
parameter, even the simple datatypes (and in practice most parameters are
simple/short), IMO is too much and more prone to (difficult to debug) bugs.
And saying that it's a matter of careful programming is the same "argument"
i used to get when trying to explain the advantage of using local variables
to old school RPG-ers. I want the compiler / language to help me as much as
possible.

So if performance was not an issue at all i would use "value" everytime,
and a pointer with "value" only if i want to pass data back (change the
data from the called procedure).








On Thu, May 2, 2013 at 4:23 AM, Barbara Morris <bmorris@xxxxxxxxxx> wrote:

On 5/1/2013 6:14 AM, whatt sson wrote:
...
if i need to pass lots of data (in principle always if i want to pass
more
than just a basic type) i pass a pointer. ... I don't see a real
downside in this approach ...

RPG doesn't have typed pointers.

Take this C function
myFn (int *p);

The exact RPG equivalent is

D myFn PR
D p 10i 0

Both the C and RPG prototypes say that the parameter is an integer
passed by reference. The C version can also be stated as "pointer to
integer passed by value". But that's not possible to code in RPG. This
RPG prototype

D myFn PR
D p * value

is not equivalent to the C prototype, because that RPG prototype simply
says "pointer passed by value". The "integer" part of the C prototype is
lost.

If you pass the address of a float to the C function, the C ocmpiler
will complain. If you pass the address of a float to the second RPG
function, the RPG compiler won't care, because you haven't told it to
expect a pointer to an integer.

If you decide to manage passing the correct data types yourself, you're
back in the bad old days of CALL + PARM, where the compiler oculd not do
any type checking.

--
Barbara
--
This is the RPG programming on the IBM i (AS/400 and iSeries) (RPG400-L)
mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-l.



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.