Microsoft KB Archive/52095

Passing Common Numeric Types from COBOL to C

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

3.00 3.00a MS-DOS

Summary: The two programs shown below demonstrate how a Microsoft COBOL program can pass common numeric types to a C routine by reference and value. This information about interlanguage calling applies to Microsoft COBOL Compiler 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 passes a long and an integer to a C routine by both value and reference: $SET LITLINK IDENTIFICATION DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 FIELD1 PIC 9(4) COMP-5 VALUE 123. 01 FIELD2 PIC 9(8) COMP-5 VALUE 123456. 01 FIELD3 PIC 9(4) COMP-5 VALUE 456. 01 FIELD4 PIC 9(8) COMP-5 VALUE 456789. PROCEDURE DIVISION. CALL “C_CFUNC” USING FIELD1, FIELD2, BY VALUE FIELD3, BY VALUE FIELD4. DISPLAY “Returned PIC 9(4):” FIELD1. DISPLAY “Returned PIC 9(8):” FIELD2. STOP RUN. The following program is C.C, which prints out integers and longs received by value and reference: #include  void CFunc(int RefInt, long RefLong, int ValInt, long ValLong) { printf(“By Reference: %i %li”, RefInt, RefLong); printf(“By Value : %i %li”, ValInt, ValLong); RefInt = 321; RefLong = 987654; } 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: By Reference: 123 123456 By Value : 456 456789 Returned PIC 9(4): 00321 Returned PIC 9(8): 000987654

Copyright Microsoft Corporation 1990.