× 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,
 
While I whole heartedly agree with having the RPG prototype define the return value there is, in this case, no harm done if it isn't defined.  So people don't need to run off and start verifying/updating prototypes that don't correctly define a return value.
 
There is a case where storage could inadvertently be overwritten but it is only when a value is being returned that exceeds 16 bytes in length.  And any developer returning "something" longer than 16 bytes by value (as opposed to a 16-byte pointer to the "something") should have his or her hands slapped.
 
I will add that one could get "interesting" results if the prototype defined the returned value as being of the incorrect data type.  Now this type of error would be worth fixing up.
 
In the given case the return value is a 4-byte integer.  Nothing bad will happen.
 
Bruce
 
 

Also, you forgot the RETURN VALUE on your RPG prototype.  Your C
prototype returns an int -- but the RPG side shows no return value.
Change it to have 10i 0 as a return value, otherwise those 4 bytes that
are returned could possibly be overwriting memory used for something
else -- and that might be hard to catch in testing, but could result in
the dreaded "unexpected results" in production.


Bruce
Bruce Vining Services
507-206-4178

--- On Tue, 11/25/08, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> wrote:

From: Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx>
Subject: Re: Calling C from RPG: what am I doing wrong?
To: "RPG programming on the AS400 / iSeries" <rpg400-l@xxxxxxxxxxxx>
Date: Tuesday, November 25, 2008, 5:28 PM

James,

options(*string) causes RPG to make a copy of your variable and add a
x'00' to the end, then pass that temporary copy. You cannot use
options(*string) for an output (or in/out) parameter.

Instead, consider passing buffy as an alphanumeric field (NOT a
pointer). If it needs to be null-terminated on the RPG side, then use
the %str() BIF to null-terminate it before you pass it.

Also, you forgot the RETURN VALUE on your RPG prototype. Your C
prototype returns an int -- but the RPG side shows no return value.
Change it to have 10i 0 as a return value, otherwise those 4 bytes that
are returned could possibly be overwriting memory used for something
else -- and that might be hard to catch in testing, but could result in
the dreaded "unexpected results" in production.

James Lampert wrote:
I have a C procedure called by an RPG program:

In the RPG program, it is prototyped thusly:

D FOO PR EXTPROC('foo')
D * VALUE OPTIONS(*STRING)
D * VALUE OPTIONS(*STRING)
D 10I 0 VALUE
D * VALUE OPTIONS(*STRING)
D * VALUE OPTIONS(*STRING)

and called thusly:

C CALLP FOO(X,Y,I,K,BUFFY)

and the C procedure is:

int foo(char *opcode, char *filename, int len, char *key, char *buffy) {
/* here we read a record from a file, putting the record into buffy */

A printf() statement in the C procedure tells me that the record
definitely gets read from the file, and it's definitely the right
record. Yet when control returns to the calling program, the record is
gone, and what was originally in BUFFY is back.

Obviously, I'm doing *something* wrong here.



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.