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.

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.

NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…