Microsoft KB Archive/57351

From BetaArchive Wiki

A C Function Returning an Integer to a COBOL Program

PSS ID Number: Q57351 Article last modified on 11-30-1990

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft C function can return an integer to COBOL. 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 invokes a C function and prints out the integer returned by that function: $SET LITLINK $SET RTNCODE-SIZE(2) IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASS-VAR PIC 9(4) COMP-5 VALUE 3. PROCEDURE DIVISION. CALL “C_Circum” USING BY VALUE PASS-VAR. DISPLAY “Radius of circle:” PASS-VAR. DISPLAY “Circumference of circle:” RETURN-CODE. STOP RUN. The following program is C.C, which computes the circumference of a circle from a passed radius and returns the circumference to the calling COBOL program: #include <stdio.h> int Circum(int Radius) { float cir; cir = 3.14159 * Radius * Radius; return((int) cir); } COB.EXE produces the following output: Radius of circle: 00003 Circumference of circle: +0028

Copyright Microsoft Corporation 1990.