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




On 01/10/2004, at 8:16 AM, David C. Shea wrote:

Now I have only one more question. I need to pass the resulting RRN back to the calling CL program. I am passing parameters into the C program (to get the file name, lib, etc) but now I need to know how to get the resulting number back to the CL.

Welcome to the joys of C! NOT!

C in general has no concept of bi-directional parameters between program objects. This is a result of limitations on the platforms where C is popular. Said limitation is the lack of dynamic program call e.g., a .exe cannot call another .exe except via system(). Bi-directional parameters are also complicated by C's preference for passing things by value instead of by reference.

You could pass the RRN back as the return value from main. So

int main ( int argc, char * argv[] )
{

   return(rrn);
}

but this trick only works for integer values. It would be better too learn how to handle this requirement generically so you can pass parameters bi-directionally.

Consider that all *PGM objects on OS/400 accept parameters by reference (MI can accept by value but I think no HLL can). Thus C receives a pointer to the variable passed by it's caller. Thus you can reference the argument pointer and copy the result into your caller's storage. So:

int main ( int argc, char * argv[] )
{

   memcpy( argv[5], &rrn, sizeof(rrn) );
   return(0);
}

or

int main ( int argc, char * argv[] )
{
   int * rrn = (int*)argv[5];

   *rrn = riofb_fwd->rrn;
   return(0);
}

Presuming argument 5 is the parameter in the calling program that should contain the RRN.

Strings can be handled in a similar manner:

int main ( int argc, char * argv[] )
{
   const char * data = "Twas brillig and the slithy toves ..."
   memcpy( argv[1], data, strlen(data) );
   return(0);
}

as can packed decimal values.

Caveats:
o C counts from 0 and argv[0] is always the current program name.
o Parameter sizes in both the caller and callee must be compatible.
o C does no blank padding of longer fields so you'll have to handle that when copying character strings of varying length.


Regards,
Simon Coulter.
--------------------------------------------------------------------
   FlyByNight Software         AS/400 Technical Specialists

   http://www.flybynight.com.au/
   Phone: +61 3 9419 0175   Mobile: +61 0411 091 400        /"\
   Fax:   +61 3 9419 0175                                   \ /
                                                             X
                 ASCII Ribbon campaign against HTML E-Mail  / \
--------------------------------------------------------------------



As an Amazon Associate we earn from qualifying purchases.

This thread ...


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.