Microsoft KB Archive/62817

Passing Signed Floating-Point Number from COBOL to C Example

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

3.00 3.00a MS-DOS

Summary: The following example shows how to pass a signed floating-point number from COBOL to C. This information on mixed-language programming applies to Microsoft COBOL versions 3.00 and 3.00a and to Microsoft C version 5.10. For more examples of passing other types of parameters between COBOL and C, query on the following word: COB2C For a more complete discussion about mixed-language programming with Microsoft COBOL, search in the Software/Data Library for the following word: COBMIXED

More Information: The following is a code example:

COBOL Code
$SET ANS85 LITLINK IDENTIFICATION DIVISION. PROGRAM-ID. COBTEST. DATA DIVISION. WORKING-STORAGE SECTION. 01 COB-FLOAT             PIC -9999V9999 01 PASS REDEFINES COB-FLOAT. 03 WHOLE-PART        PIC -9999. 03 FRACTIONAL-PART   PIC 9999. 01 PASS-NUMBER. 03 PASS-WHOLE-PART   PIC S9999 COMP-5. 03 PASS-FRACT-PART   PIC  9999 COMP-5. PROCEDURE DIVISION. MOVE -123.4567        TO COB-FLOAT. MOVE WHOLE-PART       TO PASS-WHOLE-PART. MOVE FRACTIONAL-PART  TO PASS-FRACT-PART. DISPLAY &quot;COBOL CALLING C NOW...&quot;. CALL &quot;C_ROUTINE&quot; USING PASS-WHOLE-PART PASS-FRACT-PART. STOP RUN. Compile as follows:

COBOL COBTEST.CBL;

C Code

 * 1) include  long routine (int h, int l) { double f; if (h < 0) f = h - (double) l /10000; else f = h + (double) *l /10000; printf(“float from COBOL %4.4f”,f); } Compile as follows:

cl /c /Awlf cprog.c ; Link as follows:

link /noe cobtest minitc cprog,,,lcobol llibce ;

Copyright Microsoft Corporation 1990.