user15964
user15964

Reputation: 2639

What is Self-defining INTERFACE in fortran?

I read this link, it talks about Self-defining INTERFACE.

But I got confused about the saying

A Procedure should be able to read it’s own interface specification in and INTERFACE block.

What is own interface specification? What does this link mean?

Upvotes: 0

Views: 132

Answers (1)

chw21
chw21

Reputation: 8140

Before I start: This is about explicit interfaces. If in doubt, you should use MODULES so you don't have to worry about this.

Now to the question.

If you have a function, say this:

function square(a)
    implicit none
    real, intent(in) :: a
    real :: square
    square = a * a
end function square

And this function is in a separate file, to be compiled separately from the calling routine, then it would be advisable that the calling routine is told of the interface of this function. Something like this:

interface
    function square(a)
        implicit none
        real, intent(in) :: a
        real :: square
    end function square
end interface

should be in the calling routine's declaration block. This way, the calling routine, while not knowing how the square function works, knows what types of parameters to pass to it, and what to expect back.

It is quite common to put this into a separate file, and include this file everywhere this function might be called.

Here's the issue: There are no checks that the interface block actually matches the real thing. So the idea of this proposal seems to be that in the code implementing the square function, you should be able to also include this separate file and then the compiler could check whether the interface block matches the declaration, and throw an error if wrong.

At the moment, though, including this interface block is explicitly forbidden by the standard.

Upvotes: 1

Related Questions