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



Barbara is quite right.

C has better syntax for declaring the type of thing a pointer
references. RPG doesn't have this, a pointer is just a pointer.

A C prototype will declare that it wants a pointer to an integer, for
instance.

void abracadabra(int *);

When you include this prototype, the C compiler can check your calls to
the function to see if the pointer you're passing (by value) is indeed a
pointer to an integer. Of course, C also gives you plenty of ways to
circumvent this checking.

So the method Barbara describes is far superior to passing an anonymous
pointer by value in RPG.

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Barbara Morris
Sent: Thursday, February 11, 2010 9:39 AM
To: midrange-l@xxxxxxxxxxxx
Subject: Re: iconv query

Scott Klement wrote:

However, I don't think it's unreasonable to refer to passing the
address of a variable as "passing by reference". That's the normal way

of passing things by reference in the C language.


Sorry to be late to this party :)

Maybe it depends on what language the call is being made in whether the
parameter should be thought of as "by reference" or "by value".

Say a function has a parameter defined with "my_type*". When coding the
call in C, I would code &my_variable, explicitly passing the address of
the variable by value. When coding the call in RPG or any other
language that supports passing by reference or by value using the same
call syntax, I would just code my_variable, implicitly passing the
variable by reference.

Clinging to the correct but unhelpful notion that all C parameters are
passed by value can lead to bad (but not incorrect) RPG prototypes that
just code a pointer-by-value for every parameter, leading to nasty code
like this:

// void my_function(int *);
D my_function pr
D num * value
D the_number s 10i 0
D other_number s 5p 0

my_function (%addr(the_number)); // ok
my_function (%addr(other_number)); // oops

The prototype is technically correct, but it isn't the best RPG
prototype. The second call will compile fine, and it may run without
exception depending on what value the function happens to put into
other_number and the byte following it.

Thinking of the "int *" as a parameter passed by reference leads to this
better RPG prototype:

// void my_function(int *);
D my_function pr
D num 10i 0
D the_number s 10i 0
D other_number s 5p 0

my_function (the_number); // ok
my_function (other_number); // compiler diagnostic

--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list To post a message email: MIDRANGE-L@xxxxxxxxxxxx To subscribe,
unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/midrange-l
or email: MIDRANGE-L-request@xxxxxxxxxxxx Before posting, please take a
moment to review the archives at http://archive.midrange.com/midrange-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.