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



Ok thanks guys.

I wonder if we could may be close this thread off by commenting on the
following - just to help a youthful (read ignorant) RPG programmer confirm
that he really doesn't understand what is going on with the C style apis.

Syntax


#include <iconv.h>

size_t iconv (cd, inbuf, inbytesleft,
outbuf, outbytesleft)


iconv_t cd;
char **inbuf;
size_t *inbytesleft;
char **outbuf;
size_t *outbytesleft;

cd = Is passed by value because there is no asterisk in front of it
inbuf = Is passed by reference, i.e. two asterisks means pass a pointer by
reference
inbytesleft = Is passed by reference as there is an asterisk

Neill

-----Original Message-----
From: midrange-l-bounces@xxxxxxxxxxxx
[mailto:midrange-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: 05 February 2010 19:41
To: Midrange Systems Technical Discussion
Subject: Re: iconv query

Hello,

I'm confused. With C, when calling a function, all argument
(parameter) passing is is by value. That's how C is defined.

True. By that logic, nothing in C can ever be passed by reference.

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.


So what's wrong with "C-structs are passed that way"? For it not to
be passed "that way" (by value) you need to change what you're passing --
namely to a pointer to the struct.

That's a technicality, Bruce, and you know it -- that's why you refer to
your message as "nit picking".

What's wrong with the original statement of "C-structs ar passed that
way" is that it implies that whenever a C programmer wants to pass a
data structure from one function to another, that they *always* pass it
by value. And that's simply not true. Heck, it's not even true in a
majority of cases.

You almost always see structures passed like this:

struct mydata {
int var1;
char var2[50];
};

int dosomething(struct mydata *arg) {
/* whatever */
}

int main(int argc, char **argv) {
struct mydata x;
if (dosomething(&x)) {
/* whatever */
endif;
return 0;
}

You can say "but, when you pass a pointer, you're not passing the data
structure, you're passing a pointer" but that's just a technicality.
The programmer's intent is to pass a data structure by reference. That's
the *reason* why this is being done, and it's by far the most common
means of passing a data structure in C (at least in my experience).

Vern's post was aimed at an RPG programmer trying to call a function
that was written in C, and documented by IBM using C prototypes and C
examples instead of the more common language-neutral API documentation
format.

The RPG programmer was trying to figure out how to call the function.
And in this case, he *should* pass it by value. But this is not because
"C always passes data structures by value". If you called another
function where it passed the data by address, then you should pass it by
address. Do what the function calls for, and NOT "always by value
because that's the way C does it."

As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
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.