Table 1 identifies the data types that
can be passed between C and COBOL by Reference (Indirect) and from
COBOL to C either by Value (Indirect) or by Reference (Indirect).
Table 1. Supported
data types passed between C and COBOL by reference (Indirect) and
from COBOL to C either by value (indirect) or by reference (indirect)
without #pragmaC (Pointer
to...) |
COBOL (by
content/by reference) |
---|
char |
PIC X, PIC A |
signed short int |
PIC S9(4) USAGE IS BINARY |
unsigned short int |
PIC 9(4) USAGE IS BINARY |
signed int, signed long int |
PIC S9(9) USAGE IS BINARY |
unsigned int |
PIC 9(9) USAGE IS BINARY, LENGTH
OF |
unsigned long int |
PIC 9(9) USAGE IS BINARY |
float |
COMP-1 |
double |
COMP-2 |
pointer to... |
POINTER, ADDRESS OF |
decimal |
USAGE IS PACKED-DECIMAL |
struct |
Groups |
type array[n] |
Tables (OCCURS n TIMES) |
Note: - You must specify a size for type array.
If
the COBOL program receives int parameters from
the C calling function that might have a value that is larger than
that declared as the maximum size by the COBOL picture clause, the
COBOL program must either be compiled with the TRUNC(BIN) compiler
option or each binary data item that receives int parameters
from C must be declared as USAGE IS COMP-5. Taking these actions will
guarantee that truncation of high-order digits does not occur. For
more information about the TRUNC(BIN) compiler option or about using
COMP-5 data items, see the appropriate version of the programming
guide in the Enterprise COBOL for z/OS library.
- COBOL turns on the high-order bit of the address of the last parameter
when it is passed by reference. This can cause problems in the C
program if it is using the address (since it will be treated as a
negative number). If a C program does need to use the address of the
last parameter, one of the following techniques can be used to bypass
this problem:
- If the COBOL program is an Enterprise COBOL program, instead of
passing the parameter by reference, pass the address of the item by
value. For example, use a call statement that looks like the following
code:
CALL "C" using by value address of C-PARM1
by value address of C-PARM2
- If the COBOL program is not Enterprise COBOL, code needs to be
added to mask out the high-order bit in the C routine. The sample
code shows how to do this:
#include <stdio.h>
#include <string.h>
void A1CC01BA(char* myString)
{
myString = (char*)((int)myString & 0x7fffffff);
printf("My String: %s \n", myString);
return;
}