next up previous
Next: Program Library News Up: Interfacing Fortran and Previous: 5- Input/Output

6- Initialization

On many systems the runtime libraries for a given language has to be initialized --- a task which is then performed by the main program.

6.1- Fortran main program

With a Fortran main program calling C functions directly or indirectly the following points have to be respected.

C/370

The C/370 runtime library is automatically initialized when the first C routine is called. The system resources allocated there are released again as soon as the Fortran routine, from which the C routine triggering the initialization was called, returns. Calling another C routine after that does not cause a re-initialization and the program usually crashes because the malloc heap has become invalid.

This effect can be safely avoided by calling the first C routine immediately in the Fortran main program. KERNLIB contains a dummy routine INITC for this purpose.

When executing a module containing C code the C runtime libraries have to be included in the GLOBAL library lists. The CERNLIB command is the most convenient call to this. Note that the C compiler itself is a C program and will abort with an unintelligible message if the libraries are not defined.

VMS

A Fortran program should call VAXC$CRTL_INIT (either from Fortran or from C) before calling any functions from the C runtime library. There can be strange effects if this rule is not obeyed.

6.2- C main program

Our experience with a C main program calling Fortran routines is limited. One known restriction is that the GETARG routine for retrieving the command line arguments in Fortran cannot be used. Calling this routine usually results in unresolved externals called f77_argc or similar.



Janne Saarela
Mon May 22 15:43:10 METDST 1995