Microsoft KB Archive/52173

From BetaArchive Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

C Function Returning a Long Integer to COBOL

PSS ID Number: Q52173 Article last modified on 01-09-1991

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft C function can return a long 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

The following COBOL program is COB.CBL, which invokes a C function to compute the area of a circle. It then displays the long integer returned by the C function: $SET LITLINK $SET RTNCODE-SIZE(4) IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 PASS-VAR PIC 9(4) COMP-5. PROCEDURE DIVISION. DISPLAY “Radius of circle?”. ACCEPT PASS-VAR. CALL “C_Area” USING BY VALUE PASS-VAR. DISPLAY “Area of circle:” RETURN-CODE. STOP RUN. The following program is C.C, which computes the area of a circle from a passed radius and returns the area to the calling COBOL program: #include <stdio.h> long Area(int Radius) { float cir; cir = 3.14159 * Radius * Radius; return((long) cir); } 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; COB.EXE produces the following output: Radius of circle? 110 Area of circle: +000038013

Copyright Microsoft Corporation 1991.