8

The Pascal main program,

PassProcmain.p

The commands to compile and execute PassProc.f and PassProcmain.p

program PassProcmain;

var

a, b: real;

procedure passproc(var u: real; var v: real; procedure p(var r: real; var s: real)); external fortran;

procedure AddOne(var x: real; var y: real);

begin

y := x + 1 end; { AddOne }

begin

a := 8.0; b := 0.0;

passproc(a, b, AddOne); writeln(a: 4: 1, b: 4: 1)

end. { PassProcmain }

hostname% f77 -c PassProc.f PassProc.f

passproc

hostname% pc PassProc.o PassProcmain.p -lpfc -lF77 hostname% a.out

8.0 9.0

If the procedure is not a top-level procedure, then you do not deal with how to pass it, because that requires allowing for the static link. A procedure or function passed as an argument is associated with a static link to its lexical parent’s activation record.

When an outer block procedure or function is passed as an argument, Pascal passes a null pointer in the position normally occupied by the static link of the passed routine. So that procedures and functions can be passed to other languages as arguments, the static links for all procedure or function arguments are placed after the end of the conformant array bounds pairs, if any.

The FORTRAN–Pascal Interface

203