Interprogram Communication
12.7 Calling Non-COBOL Programs from Compaq COBOL
12.7.3 Calling a C Program
Calling a program or routine that is written in C allows you to take advantage of
features of that language. Example 12–16 features a C routine that can be called
from a COBOL program.
Example 12–16 has two global external variables, _ _Argc and **_ _Argv. Note
that **_ _Argv[ ] has an extra level of indirection; it is a pointer to a pointer to an
array.
Example 12–16 C Routine to Be Called from a COBOL Program
/* crtn - c function to test use of argc and argv in c routines
*
called from Compaq COBOL
*/
#include "cobfunc.h"
#include <stdio.h>
extern int _ _Argc;
extern char **_ _Argv[];
#define argc _ _Argc
#define argv (*_ _Argv)
void crtn()
{
int i;
i = 0;
for (i = 0; i < argc; i++) {
printf("argv[%d] = %s\n", i, argv[i]);
}
}
Example 12–17 is a representation of how you can call a C program from your
Compaq COBOL application. In this case, the C routine crtn (in Example 12–16)
is called.
Example 12–17 Calling a C Program from a COBOL Program
IDENTIFICATION DIVISION.
PROGRAM-ID. CTEST.
DATA DIVISION.
WORKING-STORAGE SECTION.
.
.
.
PROCEDURE DIVISION.
MAIN SECTION.
A001-MAIN.
.
.
.
CALL "crtn".
EXIT PROGRAM.
END PROGRAM CTEST.
For information on handling LIB$INITIALIZE when calling a C program, see
Appendix B.
Interprogram Communication 12–29
Содержание COBOL AAQ2G1FTK
Страница 22: ......
Страница 30: ......
Страница 94: ......
Страница 110: ......
Страница 146: ......
Страница 180: ......
Страница 194: ...Processing Files and Records 6 1 Defi...
Страница 300: ......
Страница 490: ......
Страница 516: ......
Страница 517: ......
Страница 530: ......
Страница 534: ......
Страница 590: ......
Страница 620: ......