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



Clinging to the correct but unhelpful notion that all C parameters are
passed by value...
Barbara,

I disagree (kinda). The iconv() API is documented in the Information Center
using a C style prototype. As the call interface is documented using C
conventions I believe it is very helpful (dare I say essential) to know that
the API expects the documented parameter to be passed by value.

The caller certainly needs to know the capabilities of the calling language
and that passing a pointer to X by value is equivalent to passing X passed
by reference, but knowing how to (correctly) call the API in the first place
is rather important.

Bruce (who's also kinda sorry I brought this whole thing up in the first
place -- I was just having one of those nit-picky days having been doing
U.S. taxes that day)


On Thu, Feb 11, 2010 at 9:38 AM, Barbara Morris <bmorris@xxxxxxxxxx> wrote:

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.