Print

Print


Aleksandar Donev writes:
 > The books I have say that argument keywords must be provided in
 > interfaces, as in:
 > 
 > interface
 > subroutine test(first=a)
 > real, intent(in) :: a
 > end interface
 > 
 > but also that explicit interfaces should not be given for module
 > procedures since they are provided implicitly. So how does one use
 > module procedures with argument keywords?

Several confusions here.  Much of it probably caused by incorrect
terminology.

An explicit interface for a procedure is basically the information
about how to call the procedure (including, among other things, the
argument names).

The piece of code you show above is not an "explicit interface".  It
is an interface body in an interface block...(well sort of - it has
several syntactic problems, but that's what you are trying to write).

Writing an interface body in an interface block is one way of
providing an explicit interface, but it is not the only way.  Nor is
it often a very good, or even possible, way.  I'd guess that part of
your confusion is that you are confusing these terms and thinking
about interface bodies when you see the term "explicit interface".
They are not synonyms.

A module procedure *DOES* have an explicit interface - always.
It comes with one by virtue of being a module procedure.  And
whenever you USE the module, that goves you access to the explicit
interface information.  That's basically why you can't write an
interface body for a module procedure.  The module procedure already
has an explicit interface.  If you try to give it one with an
interface body, you'd be either duplicating or contradicting the
one it already has.

I'd really avoid the term "implicit" in this regard.  Its perhaps
correct, both gramatically and technically, to say that a module
procedure implicitly has an explicit interface - which is to say
that it does not have an implicit interface.  But its darned
confusing.  The terminology is perhaps unfortunate (and is compounded
by the distinction between an interface block and an interface body,
but thankfully that part isn't directly at issue here).

Now.  Given any procedure with an accessible explicit interface,
regardless of whether the interface was given by an interface body or
was automatic by virtue of being a module procedure, what are the
keywords?  The keywords *ARE* the dummy argument names.  You don't
specify the keywords separately in the procedure or in the interface
body.  You just write the dummy arguments normally.  By virtue of
being dummy argument names in an explicit interface, they are
available as keywords when you invoke the procedure.

So for a module procedure, you don't have to do anything special
to make the keywords available.  Just USE the module (if you don't
do that, then you can't call the procedure at all).  Then you are
free to use the keyword form in calls to it.  The dummy argument
names are the keywords.

-- 
Richard Maine
[log in to unmask]



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%