Re: Interface Question



Arjen Markus <arjen.markus@xxxxxxxxxx> wrote:

A schreef:

Inside of A.f90 looks something like this

INTERFACE
SUBROUTINE C
...................
...................
END SUBROUTINE C
END INTERFACE

Can someone explain what this INTERFACE block is meant for. I know
INTERFACE could be used to achieve "overloading" of operators or
defining generic routines. But I don't understand what's going on here.


The INTERFACE block defines how subroutine C is supposed to be used. The
compiler can then check if the code has a syntactically correct call to
the subroutine, that is: correct number of arguments, correct types,
kinds, dimensions, correct order.

Also, the interface information is necessary for some features to work
correctly; that's more than just checking. For example, if the
subroutine has an assumed shape dummy array, the compiler needs to know
that in order to pass the necessary shape information.

I might also add, in a small attempt to help clear up one confusion,
that interface blocks have two completely separate purposes. I
personally wish that they had been given different names instead of
calling them both versions of the same thing.

1. There are the interface blocks that define generics (overloads) like
the OP is thinking about. I'd have preferred that these be called
something more like generic (and they wouldn't have needed a block form;
a simple statement would do).

2. There are interface blocks that define specific interfaces. That's
like the example here. It has nothing to do with generic overloads. It
just happens to also be called aninterface block.

As best as I can tell, the two forms were mangled together so that you
could do both things at once in cases where both were needed. I think
that the minor convenience of doing both things together is inadquate
payoff for the confuson of the concepts involved, but it is too late to
do much about that.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.



Relevant Pages

  • Re: Interface Question
    ... END SUBROUTINE C ... The INTERFACE block defines how subroutine C is supposed to be used. ... There are the interface blocks that define generics like ...
    (comp.lang.fortran)
  • Re: optional or interface
    ... put the routine in a module:... ... He is talking about interface *BODIES*. ... subroutine or function, but without the "guts"; ... generics - specifically the rules for disambiguability (which I know is ...
    (comp.lang.fortran)
  • Re: Structure of large link libraries in f95
    ... Since my "user interface" is to edit the source, ... but your module only contains interface blocks. ... I use only integer and double precision, and stick to traditional naming conventions, but I frequently monkey with my code, and sometimes change the argument list of a subroutine. ... Type mismatches can be particularly devastating, since they fall into the category of addressing errors that can cause failure at a point remote from the defective line of code. ...
    (comp.lang.fortran)
  • Re: interface, public ::
    ... interface, public:: this ... module procedure thisParticularFunction ... There are two almost unrelated kinds of interface blocks. ... interface blocks that define generics. ...
    (comp.lang.fortran)
  • Re: compiler switch -c
    ... All methods must be exposed by interface. ... module procedure fruit_summary_ ... end subroutine init_fruit_ ... character, intent, optional:: message ...
    (comp.lang.fortran)