


To match simple C external variables or passed data items, just choose the appropriate usage type. For example, to share an integer variable with a C routine, declare it in COBOL as:
77 MY-SHARED-INT SIGNED-INT, EXTERNAL.
In C, this item is then declared as:
int my_shared_int;
77 MY-INT SIGNED-INT. MOVE 123 TO MY-INT. CALL "C-ROUTINE" USING, BY VALUE, MY-INT.
The ANSI C routine could then read:
void c_routine( int param1 )
{
printf( "This should be '123': %d\n", param1 );
}
Matching complex data items such as C "struct" items or arrays is more difficult. The problem arises in trying to match the FILLER that may follow the COBOL data items. For example, consider the following group item:
01 GROUP-1.
03 INT-1 SIGNED-INT.
03 INT-2 SIGNED-INT.
Assuming that each item was allocated 4 bytes, this would match the following C structure on a 32-bit machine:
struct {
int int_1;
int int_2;
} group_1;
This is straightforward. However, on a 16-bit machine, you would need this C structure:
struct {
int int_1;
int filler_1;
int int_2;
int filler_2;
} group_1;
This structure adjusts for the implied filler that happens when the 4-byte SIGNED-INT items are remapped by the runtime to 2-byte items.
If you must match complex C data types, you can take one of three approaches:
1. You can use fixed-size COMP-5 COBOL data types that match your C structures. You will then have to change your COBOL code and recompile when you move to a different target environment.
2. You can use the variable-size COBOL data types described in this section and adjust your C structures accordingly. This will require a change to your C code when you move to a new environment.
3. You can use the variable-size COBOL data types described in this section and select different target architectures with the "-Dw" compile option. In this scenario, you do not have to change code to go to a new environment--you just have to recompile with a different "-Dw" setting. One possibility would be to setup three different directories on the development machine--one for "-Dw16" objects, one for "-Dw32" objects, and one for "-Dw64" objects. This would provide you with COBOL objects for all currently supported machines.