joeschuh
asked on
Call CILE Service Program from free-form RPG
I'm trying to call a very simple C ILE service program from RPG.
The C function looks like this:
I'm able to call it using the RPG code below...
However, when I step through the C function in debug, instead of 3 and 4, a and b equal 319266122 and 1593839616. So when they get added together they result in a decimal-data error. What do I have to do to get the parms in a format that jives w/ the C function?
The C function looks like this:
int Add(const int a, const int b) {
return a + b;
}
I'm able to call it using the RPG code below...
h dftactgrp(*no) BndDir('MYLIB/MYBNDDIR')
d HelloWorldPR pr * ExtProc('HelloWorld')
d AddPR pr 5 0 ExtProc('Add')
d num1 5i 0 const
d num2 5i 0 const
d ReturnNumberPR pr 5i 0 ExtProc('ReturnNumber')
d result s 5i 0 Inz(*zero)
d n1 s 5i 0 Inz(*zero)
d n2 s 5i 0 Inz(*zero)
/Free
n1 = 3;
n2 = 4;
result = AddPR(n1:n2);
*inlr = *on;
/End-Free
However, when I step through the C function in debug, instead of 3 and 4, a and b equal 319266122 and 1593839616. So when they get added together they result in a decimal-data error. What do I have to do to get the parms in a format that jives w/ the C function?
ASKER
Gary, thank you very much. That is good information.
However, defining my RPG fields "n1" and "n2" as 10i 0 didn't change the fact that when I step through the call, I can see within the C function the values "a" and "b" equal really really large numbers, and I'm just trying to pass 3 and 4.
In debug, before I step into the C function call n1 and n2 (in my RPG program) equal 3 and 4. When I step into the function, the parameters a and b (of the C function) equal 319,268,938 and 1,593,839,616.
I basically left the c function defined w/ ints, and changed the RPG fields that i use to call the function to 10i's.
Unless I'm misunderstanding something here.
However, defining my RPG fields "n1" and "n2" as 10i 0 didn't change the fact that when I step through the call, I can see within the C function the values "a" and "b" equal really really large numbers, and I'm just trying to pass 3 and 4.
In debug, before I step into the C function call n1 and n2 (in my RPG program) equal 3 and 4. When I step into the function, the parameters a and b (of the C function) equal 319,268,938 and 1,593,839,616.
I basically left the c function defined w/ ints, and changed the RPG fields that i use to call the function to 10i's.
Unless I'm misunderstanding something here.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Both solutions provided good info. My problem ended up actually being that I was adding addresses together instead of the actual values. I was passing the parameters byref in the RPG code. I added the keyword "value" and everything worked fine.
Thanks to you both.
Thanks to you both.
ASKER
d AddPR pr 5 0 ExtProc('Add')
d num1 5i 0 value
d num2 5i 0 value
d num1 5i 0 value
d num2 5i 0 value
ILE C vs ILE RPG Numeric Data Types
C int = RPG 10I 0
C short [int] = RPG 5I 0
C unsigned [int] = RPG 10U 0
C unsigned short [int] = RPG 5U 0
C float = RPG 4F
C double = RPG 8F
C long [double] = RPG 8F
- Gary Patterson