Microsoft KB Archive/52173: Difference between revisions
m (Text replacement - "<" to "<") |
m (X010 moved page Microsoft KB Archive/Q52173 to Microsoft KB Archive/52173 without leaving a redirect: Text replacement - "Microsoft KB Archive/Q" to "Microsoft KB Archive/") |
||
(One intermediate revision by the same user not shown) | |||
Line 11: | Line 11: | ||
== Code Example == | == 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 | 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. | Copyright Microsoft Corporation 1991. |
Latest revision as of 19:25, 12 August 2020
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.