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



Hello!

I've been fiddling with C, modules, bound service programs, etc, and have come to a situation where I need the expertise of someone a bit more knowledgeable.

Given the following C Source:

0001.00 #include <stdio.h>
0002.00 #include <string.h>
0003.00 #include <stdlib.h>
0004.00
0005.00 char* getStr(int incomingVar);
0006.00
0007.00 char* getStr(int incomingVar)
0008.00 {
0009.00  char foo[25];
0010.00  sprintf(foo,"%d",incomingVar);
0011.00  return foo;
0012.00 }

And given the following ILE RPG Source:

0001.00 D getStr          PR            25A   extproc('getStr')
0002.00 D                                5I 0 VALUE
0003.00 C                   MOVEL     *BLANKS       FOOSTR           25
0004.00 C                   Eval      FOOSTR = getStr(1)
0005.00 C                   Eval      *INLR = *ON


(I've compiled the C source as a module, then created a service program using crtsrvpgm -- kudos to IBM for having an example of how to write a QSRVSRC file!)

I was expecting when I ran the rpg program, named USESTR, that FOOSTR would equal something akin to '1 ' -- that is, the visual depiction of 1 and 24 other spaces. I was greeted instead by gibberish.

I think that this has something to do with the pointer that I'm creating doesn't exist outside of the service program? Is this correct, or am I just making a big goof?

What is the "Right Way" for me to return a char* array (or even a data structure) via a bound-C service program to a RPG program? Is there even a right way to do it?

Any help would be appreciated!


Peter Grace




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:

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.