Microsoft KB Archive/57353

Example of Passing an Array of Integers from COBOL to C

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

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft COBOL program can pass an array of integers to a Microsoft C routine. This information about interlanguage calling applies to Microsoft COBOL versions 3.00 and 3.00a for MS-DOS.

More Information: For more examples of passing other types of parameters between COBOL and C, query on the following word: COB2C For a complete discussion about mixed-language programming with COBOL, search in the Software/Data Library for the following word: COBMIXED

Code Example
To demonstrate these programs from an .EXE program, compile and link as follows: COBOL COB.CBL; CL /c /Awlf C.C ; LINK /NOE COB MINITC C,,,LCOBOL LLIBCE; The following COBOL program is COB.CBL, which passes an array of integers to a C routine. The C routine then prints out the passed array. $SET LITLINK $SET ANS85 IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 T-COUNT PIC 99. 01 T-TABLE. 05 THE-TABLE PIC 9(4) COMP-5 OCCURS 5 TIMES. PROCEDURE DIVISION. PERFORM VARYING T-COUNT FROM 1 BY 1 UNTIL T-COUNT > 5 MOVE T-COUNT TO THE-TABLE(T-COUNT) END-PERFORM. CALL “C_CProc” USING T-TABLE. STOP RUN. The following program is C.C, which displays the values contained in a passed array of integers: #include  void CProc(int IntTable[4]) { int count; for (count = 0; count < 5; count++) printf(“Array [%i]: %i”, count, IntTable[count]); } COB.EXE produces the following output: Array [0]: 1 Array [1]: 2 Array [2]: 3 Array [3]: 4 Array [4]: 5

Copyright Microsoft Corporation 1990.