|
-----Original Message----- From: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Osborn, Stephen Sent: Wednesday, November 01, 2006 11:35 AM To: RPG programming on the AS400 / iSeries Subject: RE: Calling an RPG procedure with optional parameters from C codeRPG doesn't allow optional parameters to be specified before required ones either.That is true for *NOPASS but not for *OMIT
*OMIT doesn't make a parameter "optional". *OMIT means you can pass the special value of *OMIT. *NOPASS == optional. You can chose to pass something or not pass anything.
When you pass *OMIT to an RPG IV procedure, what you are really doing is passing a NULL pointer.I am not sure that is true. In the called procedure you test the field's address for NULL, not its value.
It is indeed true. In RPG you test if %addr(someParm) = *NULL; Since you are dealing with parameters passed by reference, you are asking if the pointer passed in is NULL. Note that *OMIT only works with parameters passes by reference. You can't use it for parameters passed by VALUE whereas you can use *NOPASS for parameters passed by reference or by value.
Thus, in your C/C++ program just make sure you pass a NULL pointer for the *OMITted parameter.I tried that, before I asked a question here, and it didn't work. The procedure prototype said that an INT is being passed as the first parameter and when I specified a NULL there the module would not compile.
Not sure I understand what you are saying. The RPG prototype specified an int or the C prototype?
However I just changed the first parameter of the procedure prototype to be pointer to INT and now NULL is acceptable and it is now working. As RPG, by default, uses pass by reference, in a C procedure prototype the declarations should be of type 'pointer to xxx'. All the other fields in my C procedure prototype were 'pointer to xxx' so that one was probably just a typo.
This makes sense and is what I was saying. If your RPG proto looks like D myproc pr D parm1 10i 0 options(*OMIT) D parm2 10i 0 options(*OMIT) D parm3 10i 0 Or D myproc pr D parm1 10i 0 D parm2 10i 0 D parm3 10i 0 Then in either case, your C prototype should look like (please excuse any typos, been 10+ years since I wrote any C) void MYPROC (int *parm1, int *parm2, int *parm3) C will allow you to pass a NULL point for any of the 3 parameters. HTH, Charles Wilt -- iSeries Systems Administrator / Developer Mitsubishi Electric Automotive America ph: 513-573-4343 fax: 513-398-1121
As an Amazon Associate we earn from qualifying purchases.
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.