Microsoft KB Archive/39098

COBOL 3.0 Problem Using ACCEPT AT Before CALLing C Subroutine

PSS ID Number: Q39098 Article last modified on 04-20-1993

3.00 3.00a | 3.00 3.00a MS-DOS | OS/2

Summary: When a Microsoft COBOL version 3.0 or 3.0a program CALLs a Microsoft C subroutine after using an ACCEPT AT statement, the following events may occur: 1. The program enters the C subroutine. 2. Any messages are displayed from the subroutine. 3. The program terminates, or in a loop situation, just ACCEPTs the COBOL inputs without CALLing the C subroutine again. Microsoft has confirmed this to be a problem when dynamically linking to the ADIS support files with both Microsoft COBOL versions 3.0 and 3.0a and Microsoft COBOL Professional Development System version 4.0 for MS-DOS and MS OS/2. We are researching this problem and will post new information here as it becomes available.

More Information: Two possible workarounds for this problem are as follows: 1. Do not explicitly specify the ACCEPT location with ACCEPT AT. 2. Statically LINK the ADIS support files to your program, as in the following example: LINK progname+ADIS+ADISINIT+ADISKEY+MINITC+csubname /NOE; For examples of passing parameters between COBOL and C, search in this Knowledge Base for 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 the problem, be sure to compile the C subroutine (below) with the following: CL/Awlf/c CSUB.C Also, LINK with the following command: LINK COB2C+MINITC+CSUB /NOE; The following COBOL program (COB2C.COB) demonstrates the problem. It can be compiled without a COBOL.DIR file: $SET ANS85 $SET no osvs $SET nosmalldd $SET vsc2 $SET rtncode-size(4) $SET litlink WORKING-STORAGE SECTION. 01 INKEY PIC X. 01 PASS-STR PIC x(22) VALUE “This comes from COBOL”. PROCEDURE DIVISION. PERFORM THESUB UNTIL INKEY =“Q”. STOP RUN. THESUB. DISPLAY “we are in COBOL”. CALL “C_hello” USING BY REFERENCE PASS-STR. ACCEPT INKEY AT 2501. The following is the C subroutine, CSUB.C: #pragma check_stack(off) #include “float.h” long hello( char c[]) { printf (“%s”,c); printf (“from the c program ”); return (123456789); }

Additional reference words: 3.00 3.00a Copyright Microsoft Corporation 1993.