× 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 22/08/2008, at 12:07 AM, Jevgeni Astanovski wrote:

Tried to understand how to return value from a C program to a CL.
That is CL program calls C program and C program wants to return value to it.

Need to clarify: Do you mean a "return value" from main (i.e. return (1) ) or bi-directional parameters where your CL passes a variable to C and you want C to change that variable value so that when the C program ends the CL program can use the new value?

Actually C program is mine, so whatever value can be returned - string or integer.
It must be treated by CL as boolean - YES or NO.
If I call C program with a one parameter variable from CL and then modify this parameter in C, then the changed value will be available in CL on return. Yes?

Yes. Alien concept to most C programmers because argv[] is essentially input-only on other platforms. All you have to do is copy the output value to the dereferenced argv[] element. Your C program does need to KNOW the data type expected/passed by the caller and how much space is allocated by the caller. In CL, RPG, and COBOL this parameter matching is handled by the definition of the entry point. In C you have to deal with it yourself.

But is there a way to receive the return() value?
That is if I complete my C program with return(172), then CL somehow knows, that 172 is returned?

Ah, OK. This is possible but not as straight-forward as you might hope. Refer to Page 298 in the V.4 C Programmer's Guide. You have to call the QUSRJOBI API with format JOBI0600. Why IBM didn't just reuse the RTNCODE parameter (or add a new one) on the RTVJOBA command is beyond me (perhaps because RTNCODE is a decimal(5,0) and is too small to hold all possible values returned from main).


Below is an extract from the manual (ILE/C programming guide, v.4, p.265-266), it should be the thing I'm looking for
----------------------------------------------

<<< stuff deleted >>>

------------------------------------------------
But I cannot understand, where the command SQUARE calls C program SQIFT and HOW it reads returned value.

The command calls SQIFT when it is run because SQIFT is named on the PGM keyword of the CRTCMD command. CRTCMD converts command source into a *CMD object and links it to the program (the command processing program) specified on the PGM keyword.

I think the confusion here is caused by CL **command** and CL **program**. You want to return a value from C to a CL **program** but the example is using a CL **command**. The command processing program is in C and is not returning a value from main. It is receiving a value from the main() of a second C program SQ.

Sorry for my english, its not native. May be that's the problem :-(


Much better than me trying to communicate with you in your native language!

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

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




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.