next up previous contents
Next: Subroutines Up: Actual arguments, formal (dummy) Previous: Actual arguments, formal (dummy)   Contents

Implicit Interfaces

Implicit interfaces are the old, F77 way of communication. Separate procedures are desired to be as independent as possible from one another (so that they can be written, compiled and maintained independently); in particular, a procedure is totally ignorant of how a different procedure looks like.

Consider our norm example. The main program knows that norm2 is an external function that returns a real value, but it has no information about the arguments.

Special problems arise when procedures call each other; the caller has very limited knowledge on the called procedure; it passes a list of actual argument addresses to the called procedure; the called procedure retrieves this addresses in order, and assumes they are the addresses of the formal (dummy) arguments.

The disadvantage of this approach is that the compiler is able to perform only limited consistency checks. In F77, it is easy to make mistakes undetectable by the compiler when working with argument lists.

Consider, for example, the following subroutine

real function pow(x,n) !assume n >= 1
    implicit none
    real::x
    integer::n,i
    print*,'Args: X=',x,' N= ',n
    pow=x
    do i=2,n
        pow=pow*x
    end do
end function pow

program powtest
    implicit none
    real::x=2.0
    integer::n=3
    real,external::pow
    print*,'pow= ',pow(x,n)    
    print*,' wrong pow= ',pow(n,x) !mistake: we flipped the
                                   !arguments around.
end program powtest

The accidental switch of arguments cannot be detected by the compiler and produces most curious results.


next up previous contents
Next: Subroutines Up: Actual arguments, formal (dummy) Previous: Actual arguments, formal (dummy)   Contents
Adrian Sandu 2001-08-26