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



You have 5I0 which is a "short" in C, not an "int".
-Bob


-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx]
On Behalf Of Chris Wolcott
Sent: Monday, March 29, 2004 1:20 PM
To: rpg400-l@xxxxxxxxxxxx
Subject: ILE C/400 calling RPGLE

I've tried to find this on the web and in the archives, but all I can
find is RPG calling C, not the other way around.  I can't find ANYTHING
on the way parms are handled in each language.  (I thought I'd read that
RPG always passes by reference, but C by default passes by value, but I
can not seem to be able to verify that.)  

In 'C' I'd have to allocate memory to return a value, else the associate
memory goes away when the call is over and would give me such an MCH3601
error.  The allocated section of memmory is 'lost' until the job
terminates or it is expressly FREE'd.  If the code is called multiple
times, you start to lose memory.  How does RPG get around this? 

QUESTION:

I have applications in both ILE C/400 and RPGLE.  I'm trying to write a
SRVPGM in RPG that is callable by either language.  (I am more
comfortable in RPG than C.)  For returning an integer, I can define the
prototype to be '5I 0' and it works fine.  However, when I try to return
a string from RPG to a C program I get an MCH3601 - Pointer not set for
location referenced.  (It gets the parms and does all the work, it fails
on the RETURN statement.)  The routine works fine for other RPGLE and
CLLE programs.  What am I doing wrong?



RPG: D MYFUNCT1        PR             5I 0       
     D   PARM1                       15A   CONST 
(Accepting a 15 character value and returning an INTEGER value)

RPG: D MYFUNCT2        PR             4A        
     D   PARM1                       15A   CONST
(Accepting a 15 character value and returning a 4 byte HEX value)

C:   int           MYFUNCT1(char *);  <- NOTE: NOT a pointer!?

C:   unsigned int *MYFUNCT2(char *);  
(Unsigned Integers are 4 bytes long, same as the 4 char field in RPG.  I
have a C routine called by RPG that treats them both this same way and
it works.)

 

_______________________________________________
This is the RPG programming on the AS400 / iSeries (RPG400-L) mailing list
To post a message email: RPG400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/rpg400-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.