Data Type Compatibility
Each high-level language has different data types. When you want to pass data between programs that are written in different languages, you must be aware of these differences.
Some data types in the ILE C programming language have no direct equivalent in other languages. However, you can simulate data types in other languages that use ILE C data types.
The following table shows the ILE C data type compatibility with ILE RPG.
ILE C declaration in prototype | Free-form ILE RPG syntax | ILE RPG D spec, columns 33 to 39 | Length | Comments |
---|---|---|---|---|
char[n]
char * |
|
|
n | An array of characters where n=1
to 16773104. If it is a null-terminated string parameter, code the prototyped parameter as a pointer with the VALUE and OPTIONS(*STRING) keywords. |
char |
|
|
1 | An Indicator. |
char[n] |
|
|
n | A zoned decimal. |
_Packed struct {unsigned short i; char[n]} |
|
|
n+2 | A variable length field where i
is the intended length and n is the maximum length. Note: If n is greater than 65535, the first element of the struct is an unsigned int, and the length is n+4. |
_Packed struct {unsigned int i; char[n]} |
|
|
n+4 | A variable length field where i is the intended length and n is the maximum length. |
wchar_t[n] |
|
|
2n | An array of UCS-2 characters. Note: The RPG UCS-2 type also supports UTF-16 data by specifying CCSID(1200). |
_Packed struct {unsigned short i; wchar_t[n]} |
|
|
2n+2 | A variable length UCS-2 field where
i is the intended length and n is the maximum length. Note: If n is greater than 65535, the first element of the struct is an unsigned int, and the length is 2n+4. Note: The RPG UCS-2 type also supports UTF-16 data by specifying CCSID(1200). |
_Packed struct {unsigned int i; wchar_t[n]} |
|
|
2n+4 | A variable length UCS-2 field where
i is the intended length and n is the maximum length. Note: The RPG UCS-2 type also supports UTF-16 data by specifying CCSID(1200). |
wchar_t[n] |
|
|
2n | An array of graphic characters. |
_Packed struct {unsigned short i; wchar_t[n]} |
|
|
2n+2 | A variable length graphic field
where i is the intended length and n is the maximum length. Note: If n is greater than 65535, the first element of the struct is an unsigned int, and the length is 2n+4. |
_Packed struct {unsigned int i; wchar_t[n]} |
|
|
2n+4 | A variable length graphic field where i is the intended length and n is the maximum length. |
char[n] |
|
|
8, 10 | A date field. |
char[n] |
|
|
8 | A time field. |
char[n] |
|
|
20-32 | A time stamp field. |
short int |
|
|
2 | An integer field. |
short unsigned int |
|
|
2 | An unsigned integer field. |
int |
|
|
4 | An integer field. |
unsigned int |
|
|
4 | An unsigned integer field |
long int |
|
|
4 | An integer field. |
long unsigned int |
|
|
4 | An unsigned integer field. |
long long int |
|
|
8 | An 8-byte integer field. |
long long unsigned int |
|
|
8 | An 8-byte unsigned integer field. |
struct {unsigned int : n}x; | Not supported. | Not supported. | 4 | A 4-byte unsigned integer, a bitfield. |
float | FLOAT(4) | 4F | 4 | A 4-byte floating point. |
double | FLOAT(8) | 8F | 8 | An 8-byte double. |
long double | FLOAT(8) | 8F | 8 | An 8-byte long double. |
_Decimal32 | Not supported | Not supported | 4 | A 4-byte decimal floating point. |
_Decimal64 | Not supported | Not supported | 8 | An 8-byte decimal floating point. |
_Decimal128 | Not supported | Not supported | 16 | A 16-byte decimal floating point. |
enum | INT(p) | pI | 1, 2, 4 | Enumeration. For n = 1,2,4: p = 3,5,10 Define ILE RPG named constants with the enum values. |
* |
|
|
16 | A pointer. |
decimal(n,p) |
|
|
n/2+1 | A packed decimal. n must be less than or equal to 30. |
union.element | Keyword POS(1) | <type> with keyword OVERLAY(data structure name) | element length | An element of a union. |
data_type[n] | <type> with keyword DIM(n) | <type> with keyword DIM(n) | 16 | An array to which C passes a pointer. |
struct | data structure | data structure | n | A structure. Use the _Packed qualifier
on the struct if the RPG data structure does not have the ALIGN keyword. Use the ALIGN keyword on the RPG data structure if the C struct does not have the _Packed qualifier. |
pointer to function |
|
with
keyword PROCPTR |
16 | A 16-byte pointer. |
The following table shows the ILE C data type compatibility with ILE COBOL.
ILE C declaration in prototype | ILE COBOL LINKAGE SECTION | Length | Comments |
---|---|---|---|
char[n]
char * |
PIC X(n). | n | An array of characters where n=1 to 3,000,000 |
char | PIC 1 INDIC .. | 1 | An indicator. |
char[n] | PIC S9(n) DISPLAY | n | A zoned decimal. |
wchar_t[n] | PIC G(n) | 2n | A graphic data type. |
_Packed struct {short i; char[n]} | 05 VL-FIELD.
10 i PIC S9(4) COMP-4. 10 data PIC X(n). |
n+2 | A variable length field where i is the intended length and n is the maximum length. |
char[n] | PIC X(n). | 6 | A date field. |
char[n] | PIC X(n). | 5 | A day field. |
char | PIC X. | 1 | A day-of-week field. |
char[n] | PIC X(n). | 8 | A time field. |
char[n] | PIC X(n). | 26 | A time stamp field. |
short int | PIC S9(4) COMP-4. | 2 | A 2-byte signed integer with a range of -9999 to +9999. |
short int | PIC S9(4) BINARY. | 2 | A 2-byte signed integer with a range of -9999 to +9999. |
int | PIC S9(9) COMP-4. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
int | PIC S9(9) BINARY. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
int | USAGE IS INDEX | 4 | A 4-byte integer. |
long int | PIC S9(9) COMP-4. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
long int | PIC S9(9) BINARY. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
struct {unsigned int : n}x; | PIC 9(9) COMP-4.
PIC X(4). |
4 | Bitfields can be manipulated using hex literals. |
float | USAGE IS COMP-1 | 4 | A 4-byte floating point. |
double | USAGE IS COMP-2 | 8 | An 8-byte double. |
long double | Not supported. | 8 | An 8-byte long double. |
enum | Not supported. | 1, 2, 4 | Enumeration. |
* | USAGE IS POINTER | 16 | A pointer. |
decimal(n,p) | PIC S9(n-p)V9(p) COMP-3 | n/2+1 | A packed decimal. |
decimal(n,p) | PIC S9(n-p) 9(p) PACKED-DECIMAL | n/2+1 | A packed decimal. |
union.element | REDEFINES | element length | An element of a union. |
data_type[n] | OCCURS | 16 | An array to which C passes a pointer. |
struct | 01 record
05 field1 05 field2 |
n | A structure. Use the _Packed qualifier on the struct. Structures passed should be passed as a pointer to the structure if you want to change the contents of the structure. |
pointer to function | PROCEDURE-POINTER | 16 | A 16 byte pointer to a procedure. |
Not supported. | PIC S9(18) COMP-4. | 8 | An 8 byte integer. |
Not supported. | PIC S9(18) BINARY. | 8 | An 8 byte integer. |
The following table shows the ILE C data type compatibility with ILE CL.
ILE C declaration in prototype | CL | Length | Comments |
---|---|---|---|
char[n]
char * |
*CHAR LEN(&N) | n | An array of characters where n=1 to 32766. A null-terminated string. For example, CHGVAR &V1 VALUE (&V *TCAT X'00') where &V1 is one byte bigger than &V. |
char | *LGL | 1 | Holds '1' or '0'. |
_Packed struct {short i; char[n]} | Not supported. | n+2 | A variable length field where i is the intended length and n is the maximum length. |
integer types | *INT LEN(&N) | 2, 4, 8 | A 2-, 4-, or 8- byte signed integer. (CL does not support 1 byte integer type) |
*UINT LEN(&N) | 2, 4, 8 | A 2-, 4-, or 8- byte unsigned integer. (CL does not support 1 byte integer type) | |
float constants | CL constants only. | 4 | A 4- or 8- byte floating point. |
decimal(n,p) | *DEC | n/2+1 | A packed decimal. The limit of n is 15 and p is 9. |
union.element | Not supported. | element length | An element of a union. |
struct | Not supported. | n | A structure. Use the _Packed qualifier on the struct. |
pointer to function | Not supported. | 16 | A 16-byte pointer. |
The following table shows the ILE C data type compatibility with OPM RPG/400®.
ILE C declaration in prototype | OPM RPG/400 I spec, DS subfield columns spec | Length | Comments |
---|---|---|---|
char[n]
char * |
1 10 | n | An array of characters where n=1 to 32766. |
char | *INxxxx | 1 | An Indicator that is a variable starting with *IN. |
char[n] | 1 nd (d>=0) | n | A zoned decimal. The limit of n is 30. |
_Packed struct {unsigned short i; char[n]} | Not supported. | n+2 | A variable length field where i is the intended length and n is the maximum length. |
_Packed struct {unsigned int i; char[n]} | Not supported. | n+4 | A variable length field where i is the intended length and n is the maximum length. |
wchar_t[n] | Not supported. | 2n | An array of UCS-2 characters. |
_Packed struct {unsigned short i; wchar_t[n]} | Not supported. | 2n+2 | A variable length UCS-2 field where i is the intended length and n is the maximum length. |
_Packed struct {unsigned int i; wchar_t[n]} | Not supported. | 2n+4 | A variable length UCS-2 field where i is the intended length and n is the maximum length. |
wchar_t[n] | Not supported. | 2n | An array of graphic characters. |
_Packed struct {unsigned short i; wchar_t[n]} | Not supported. | 2n+2 | A variable length graphic field where i is the intended length and n is the maximum length. |
_Packed struct {unsigned int i; wchar_t[n]} | Not supported. | 2n+4 | A variable length graphic field where i is the intended length and n is the maximum length. |
char[n] | Not supported. | 6, 8, 10 | A date field. |
char[n] | Not supported. | 8 | A time field. |
char[n] | Not supported. | 26 | A time stamp field. |
short int | B 1 20 | 2 | A 2-byte signed integer with a range of -9999 to +9999. |
int | B 1 40 | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
long int | B 1 40 | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
long long int | Not supported. | 8 | An 8-byte integer field. |
struct {unsigned int : n}x; | Not supported. | 4 | A 4-byte unsigned integer, a bitfield. |
float | Not supported. | 4 | A 4-byte floating point. |
double | Not supported. | 8 | An 8-byte double. |
long double | Not supported. | 8 | An 8-byte long double. |
_Decimal32 | Not supported. | 4 | A 4-byte decimal floating point. |
_Decimal64 | Not supported. | 8 | An 8-byte decimal floating point. |
_Decimal128 | Not supported. | 16 | A 16-byte decimal floating point. |
enum | Not supported. | 1, 2, 4 | Enumeration. |
* | Not supported. | 16 | A pointer. |
decimal(n,p) | P 1 n/2+1d | n/2+1 | A packed decimal. n must be less than or equal to 30. |
union.element | data structure subfield starting at position 1 | element length | An element of a union. |
data_type[n] | E-SPEC array | 16 | An array to which C passes a pointer. |
struct | data structure | n | A structure. Use the _Packed qualifier on the struct. |
pointer to function | Not supported. | 16 | A 16 byte pointer. |
The following table shows the ILE C data type compatibility with OPM COBOL/400.
ILE C declaration in prototype | OPM COBOL LINKAGE SECTION | Length | Comments |
---|---|---|---|
char[n]
char * |
PIC X(n). | n | An array of characters where n=1 to 3,000,000 |
char | PIC 1 INDIC .. | 1 | An indicator. |
char[n] | PIC S9(n) USAGE IS DISPLAY | n | A zoned decimal. The limit of n is 18. |
_Packed struct {short i; char[n]} | 05 VL-FIELD.
10 i PIC S9(4) COMP-4. 10 data PIC X(n). |
n+2 | A variable length field where i is the intended length and n is the maximum length. |
char[n] | PIC X(n). | 6, 8, 10 | A date field. |
char[n] | PIC X(n). | 8 | A time field. |
char[n] | PIC X(n). | 26 | A time stamp field. |
short int | PIC S9(4) COMP-4. | 2 | A 2 byte signed integer with a range of -9999 to +9999. |
int | PIC S9(9) COMP-4. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
long int | PIC S9(9) COMP-4. | 4 | A 4-byte signed integer with a range of -999999999 to +999999999. |
struct {unsigned int : n}x; | PIC 9(9) COMP-4.
PIC X(4). |
4 | Bitfields can be manipulated using hex literals. |
float | Not supported. | 4 | A 4-byte floating point. |
double | Not supported. | 8 | An 8-byte double. |
long double | Not supported. | 8 | An 8-byte long double. |
enum | Not supported. | 1, 2, 4 | Enumeration. |
* | USAGE IS POINTER | 16 | A pointer. |
decimal(n,p) | PIC S9(n-p)V9(p) COMP-3 | n/2+1 | A packed decimal. The limits of n and p are 18. |
union.element | REDEFINES | element length | An element of a union. |
data_type[n] | OCCURS | 16 | An array to which C passes a pointer. |
struct | 01 record | n | A structure. Use the _Packed qualifier on the struct. Structures passed should be passed as a pointer to the structure if you want to change the contents of the structure. |
pointer to function | Not supported. | 16 | A 16-byte pointer. |
Not supported. | PIC S9(18) COMP-4. | 8 | An 8 byte integer. |
The following table shows the ILE C data type compatibility with CL.
ILE C declaration in prototype | CL | Length | Comments |
---|---|---|---|
char[n]
char * |
*CHAR LEN(&N) | n | An array of characters where n=1 to 32766. A null terminated string. For example, CHGVAR &V1 VALUE (&V *TCAT X'00') where &V1 is one byte bigger than &V. The limit of n is 9999. |
char | *LGL | 1 | Holds '1' or '0'. |
_Packed struct {short i; char[n]} | Not supported. | n+2 | A variable length field where i is the intended length and n is the maximum length. |
integer types | *INT LEN(&N) | 2, 4 | A 2- or 4- byte signed integer. (CL does not support 1 byte integer type) |
*UINT LEN(&N) | 2, 4 | A 2- or 4- byte unsigned integer. (CL does not support 1 byte integer type) | |
float constants | CL constants only. | 4 | A 4- or 8- byte floating point. |
decimal(n,p) | *DEC | n/2+1 | A packed decimal. The limit of n is 15 and p is 9. |
union.element | Not supported. | element length | An element of a union. |
struct | Not supported. | n | A structure. Use the _Packed qualifier on the struct. |
pointer to function | Not supported. | 16 | A 16-byte pointer. |
The following table shows how arguments are passed from a command line CL call to an ILE C program.
Command Line Argument | Argv Array | ILE C Arguments |
---|---|---|
argv[0] | "LIB/PGMNAME" | |
argv[1..255] | normal parameters | |
'123.4' | argv[1] | "123.4" |
123.4 | argv[2] | 0000000123.40000D |
'Hi' | argv[3] | "Hi" |
Lo | argv[4] | "LO" |
A CL character array (string) will not be NULL-ended when passed to an ILE C program. A C program that will receive such arguments from a CL program should not expect the strings to be NULL-ended. You can use the QCMDEXC to ensure that all the arguments will be NULL-ended.
The following table shows how CL constants are passed from a compiled CL program to an ILE C program.
Compile CL Program Argument | Argv Array | ILE C Arguments |
---|---|---|
argv[0] | "LIB/PGMNAME" | |
argv[1..255] | normal parameters | |
'123.4' | argv[1] | "123.4" |
123.4 | argv[2] | 0000000123.40000D |
'Hi' | argv[3] | "Hi" |
Lo | argv[4] | "LO" |
A command processing program (CPP) passes CL constants as defined in Table 8. You define an ILE C program as a command processing program when you create your own CL command with the Create Command (CRTCMD) command to call the ILE C program.
The following table shows how CL variables are passed from a compiled CL program to an ILE C program. All arguments are passed by reference from CL to C.
CL Variables | ILE C Arguments |
---|---|
DCL VAR(&v) TYPE(*CHAR) LEN(10) VALUE('123.4') | 123.4 |
DCL VAR(&d) TYPE(*DEC) LEN(10) VALUE(123.4) | 0000000123.40000D |
DCL VAR(&h) TYPE(*CHAR) LEN(10) VALUE('Hi') | Hi |
DCL VAR(&i) TYPE(*CHAR) LEN(10) VALUE(Lo) | LO |
DCL VAR(&j) TYPE(*LGL) LEN(1) VALUE('1') | 1 |
CL variables and numeric constants are not passed to an ILE C program with null-ended strings. Character constants and logical literals are passed as null-ended strings, but are not padded with blanks. Numeric constraints such as packed decimals are passed as 15,5 (8 bytes).