8

The commands to compile and execute StrVar.f and StrVarmain.p

hostname% f77 -c StrVar.f

StrVar.f:

strvar:

hostname% pc StrVar.o StrVarmain.p -lpfc -lF77

hostname% a.out abcdefghij abcdefghijklmnopqrstuvwxyz oyvay

length(v)= 5

Character Dummy Arguments

When you call FORTRAN 77 routines with character dummy arguments from Pascal programs—that is, routines in which string arguments are specified as character*(*) in the FORTRAN source, there is no explicit analogue in Pascal.

So, if you try to simply pass an actual string and specify the FORTRAN routine as extern fortran, the program fails, because implementation of this type of arguments implies that the actual length of the string is implicitly passed as an extra value argument after the string pointer.

To specify this routine in Pascal, declare it as having two arguments: a VAR argument of string type for the string pointer, and an extra value argument of integer32 type for the string length.

It is incorrect to specify the routine as extern fortran because Pascal passes all arguments to FORTRAN routines by reference. Consequently, to pass this type of argument, you must:

Declare two arguments as described above, specifying the routine as simply external (without the fortran directive)

Add a trailing underscore to the routine name in a Pascal program

The FORTRAN–Pascal Interface

189