Microsoft KB Archive/61659

Example of Passing a String from COBOL 3.00 to C 5.10

PSS ID Number: Q61659 Article last modified on 12-06-1990

3.00 3.00a MS-DOS

Summary: The two programs below show how a string can be passed from a COBOL main program to a called C function. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS and to Microsoft C version 5.10. To see related articles, query on the following word: COB2C

More Information: The sample code below shows how a COBOL string (PIC X) can be passed to a called C function. Compile and link the programs as follows under MS-DOS: COBOL COB.CBL; CL /c /Awlf C.C ; LINK /NOE COB C MINITC,,,LCOBOL LLIBCE; The output from the two programs is as follows: String to C: abcdef From COBOL: abcdef

Code Example
*code for COB.CBL $SET LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. &quot;_COBPROG&quot;. DATA DIVISION. WORKING-STORAGE SECTION. 01 FIELD1. 05 str-data pic x(6) value &quot;abcdef&quot;. 05 filler pic xx value x&quot;00&quot;. PROCEDURE DIVISION. move &quot;abcdef&quot; to field1. DISPLAY &quot;String to C: &quot; FIELD1. call &quot;c_cfunc&quot; using field1. STOP RUN. /* Code for C.C / #include  void cfunc(char far Cptr) { printf(“From COBOL: %s”,Cptr); }

Copyright Microsoft Corporation 1990.