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