Give a sample on how COBOL call C function.
Including:
1. C function definition
2. parameter passing, char * pointer, int, null pointer
1. Define C function (myfun.c)
void myfun(const unsigned char mapping[], unsigned char buffer[], unsigned int len)
{
/* put your codes here*/
}
2. Compile C function into a shared library.
gcc -o myfun.so -shared -fpic myfun.c
3. COBOL caller codes
...
WORKING-STORAGE SECTION.
01 PARAM1 PIC X(4) VALUES 'AAAA'.
01 PARAM2 PIC X(4) VALUES 'BBBB'.
01 PARAM3 PIC 9(4) COMP-5.
...
PROCEDURE DIVISION.
MOVE 4 TO PARAM3.
MOVE "ABCD" TO PARAM2.
CALL 'myfun' USING PARAM1
PARAM2
BY VALUE PARAM3.
MOVE "abcd" TO PARAM2.
CALL 'myfun' USING BY VALUE 0 *> pass null pointer
BY REFERENCE PARAM2
BY VALUE 4.
STOP RUN.
EXIT.