Solved

converting from C++ prototypes to ILE RPG prototypes

Posted on 2004-09-21
10
868 Views
Last Modified: 2008-01-09
Hi Guys,

Does anybody has any information about converting C++ prototypes to ILE RPG prototypes?
How do we resolve at link time the mangled symbol name of C++ referenced in ILE RPG?

Thanks!

Dhumal
0
Comment
Question by:dhumal
  • 3
  • 3
10 Comments
 
LVL 14

Expert Comment

by:daveslater
ID: 12122135
Here is an example on how you access the
C bsearch function, link it to you might work it out from there

 D bsearch         pr              *   extproc('bsearch')          
 D  SearchArg                      *   value                        
 D  DataStart                      *   value                        
 D  Elements                     10u 0 value                        
 D  Elemsize                     10u 0 value                        
 D  CompFunc                       *   ProcPtr value                

0
 
LVL 14

Expert Comment

by:daveslater
ID: 12123906
Hi
I dug this out

C             RPGIV             Notes
--------------------------------------------------------
int, long             10I 0 Value       See note 1.
unsigned int       10U 0 Value       See note 1.
double             8F Value            See note 1.
char             10U 0 Value       See note 2.
short             10I 0 Value      See note 2.
int *             10I 0             See note 3.
unsigned *       10U 0             See note 3.
double *             8F             See note 3.
char *             * Value             Options(*String) can also be
                        used; see note 4.
void *             * Value             See note 3.
(*)             * Value
            ProcPtr            See note 5.      

The following notes correspond to the references in Table 5:

1. The normal method of parameter passing in RPG IV is known as "by
reference". This means that a pointer to the data item is passed to the called
routine, not the actual data itself. C, on the other hand, passes parameters "by
value", which is the data itself is passed to the caller. In order for RPG to
correctly pass such parameters, the keyword VALUE must be coded on the
prototype. See also note 3.

2. In theory, char (which is a single byte character) should be represented in
RPG IV as 1A and short (which is a short integer) as 5I 0. However, in
practice, it is usually necessary to code such parameters as 10U 0 for char
and 10I 0 for short since the C compiler lengthens these parameter types. If
you are only using standard C library routines, this is unlikely to affect you
since the libraries rarely use these data types. However, if you have some
"home grown" C routines, you may run into this problem.
Exploring new ways to exploit your AS/400 system 121

3. C classifies its pointers by the type of data to which it "points". Therefore, int *
represents a pointer to an integer data item. RPG IV does not differentiate
pointers this way so all RPG data pointers are equivalent to the C void *
definition. As noted above, C expects parameters to be passed by value.
However, passing a field "by reference" and passing a pointer to that field "by
value" are equivalent. Since passing a parameter by field name rather than by
using %Addr(fieldname) is somewhat more intuitive to RPG programmers. We
used this notation in the table.
This is demonstrated in the following example. CProto1 and CProto2 both
reference the same C function (Cfunction), which takes a single parameter, an
int. The CALLP operations in the example illustrate the differences in
invocation.
Note: Both of the following CALLP operations successfully call the same
function passing the same data.
D CProto1 Pr ExtProc('Cfunction')
D PtrToInt * Value
D CProto2 Pr ExtProc('Cfunction')
D 10I0
D MyParm1 S 10I 0
C CallP CProto1(%Addr(MyParm1))
C CallP CProto2(MyParm1)
The following variation illustrates the additional flexibility gained by adding the
CONST keyword. The CONST keyword tells the compiler to allow a constant
value or a variable with a different format (in terms of numeric type, length, or
decimal positions) to be passed on the call.  Now, not only can MyParm1
be used, but MyParm2 (a packed field) and the literal 25 can also be used.
The compiler generates the additional logic to convert the field to the correct
format (if required) and pass it to the C function.
D CProto3 Pr ExtProc('Cfunction')
D 10I 0 Const
D MyParm1 S 10I 0
D MyParm2 S 5P 0
C CallP CProto3(MyParm1)
C CallP CProto3(MyParm2)
C CallP CProto3(25)

4. C does not really have the concept of a fixed-length character string in the way
that RPG does. Most C functions expect strings to be variable in length and
terminated by a null character (hex ’00’). RPG IV prototypes support the
OPTIONS(*STRING) parameter to simplify the programmer’s life when
interfacing to such routines. Using this option allows the programmer to
specify either a field name or a pointer for the parameter. If a field name is
used, the compiler generates code to move the field to a temporary area, add
the null terminator, and then pass the address of this temporary area as the
parameter.
Note: The *STRING option is available in RPG compilers on systems V3R7 or
later. If you are on V3R2 or V3R6, you need to add the null terminator
yourself.

5. The keyword PROCPTR is used to qualify an RPG pointer (*) definition when
the parameter in question is a procedure pointer. These are required by some
C functions.
0
 

Author Comment

by:dhumal
ID: 12124857
Hi Dave,
 appreciate your help!
Could you please forward me the link where you got this information.
as i do not see the prototype conversion for char[].
Thanks once again
dhumal
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 14

Assisted Solution

by:daveslater
daveslater earned 75 total points
ID: 12127621
Hi
It is a book on my hard drive - I do not have a link - sorry
0
 
LVL 27

Accepted Solution

by:
tliotta earned 75 total points
ID: 12129348
Dhumal:

Written (I believe) by Barbara Morris, an RPG team member at IBM labs:

http://www.opensource400.org/callc.html

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 12129353
(p.s. BOOKMARK that and save copies of the bookmark!)

Tom
0
 
LVL 27

Expert Comment

by:tliotta
ID: 13929143
Added note...

Both the VisualAge C++ and the ILE C++ guides describe access to name demangling functions. The <demangle.h> member in the QSYSINC library has detailed discussion.

Tom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cwbx.dll not working on 64-bit 6 1,971
RPG IV and RPG ILE book 4 411
Programmer 26 519
Comments on the use of ftp server/client on OS/400 AS/400 4 96
With more and more people tethered to the internet, advertisers can reach you in new and creative ways. Push notifications on your smartphone, customized advertisements based on your previous searches, and email inboxes filled with promotional pitch…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now