Microsoft KB Archive/31813

Microsoft FORTRAN Can Call Microsoft C Library Routines PSS ID Number: Q31813 Article last modified on 04-08-1993

3.30

MS-DOS

Summary: The following information demonstrates how to call C functions from a FORTRAN program. Spawnlp creates and executes a child process. In the following example, the parent program is suspended while the child program executes. When the child program terminates, the parent program resumes execution. Spawnlp is declared in C as follows:

int spawnlp (mode, path, arg0, argl, ..., argn) int mode; char *path, *arg0, ..., *argn; The interface to FORTRAN is declared with the following program fragment:

integer*2 spawn INTERFACE TO INTEGER*2 FUNCTION SPAWN [C, VARYING, ALIAS: `spawnlp'] (mode) integer*2 mode end where the following is true:


 * 1) Spawn is the function name used from FORTRAN. The return type of spawn is declared to be integer*2.
 * 2) [c] indicates the C language.
 * 3) [varying] indicates that a variable number of arguments can be passed.
 * 4) An [alias] is used because the C name for the function spawnlp has seven characters; names in FORTRAN are only significant to six characters.

More Information: The string arguments are undeclared in the interface and assumed to be passed from FORTRAN by value. The function can now be invoked as follows:

i=spawn(0,loc( exemod’c), loc(`demoexec.exe’c), int4(0)

The C spawnlp function expects addresses of strings, not actual characters, so the LOC function is used. C strings differ from normal FORTRAN strings; these are specified by the “c” after each closing quote. INT4(0) is used to pass the last parameter, a C NULL pointer (32-bit integer zero). Microsoft FORTRAN Version 3.30, Microsoft Pascal Version 3.30, the Microsoft Macro Assembler Version 4.00, and the Microsoft C Compiler Version 3.00, are designed so that libraries and subprograms written in any one of them can be used in any other. Any C routine (not just spawn) can be interfaced to FORTRAN. These languages are supported under both MS-DOS and XENIX for additional program portability.

=
================================================================

Copyright Microsoft Corporation 1993.