Arjen Markus <
arjen.m...@gmail.com> wrote:
> Op donderdag 31 mei 2012 10:27:23 UTC+2 schreef Phillip Helbig---undress
to reply het volgende:
> > I've never had occasion to use this until now, and don't recall seeing
> > any examples. My guess is that a procedure dummy argument can be
> > optional just like any other. How would this be declared? A
> > hand-written INTERFACE block (I think this is the only time one needs to
> > write an INTERFACE block by hand; of course this is not necessary if the
> > routine is in a module which is used, but for library-type routines with
> > optional procedure arguments this can't be done) and an additional,
> > separate OPTIONAL statement?
>
> I do not know if it is possible - checking for the presence or absence
> seems odd too
I don't know what is so odd about it. Argument presence is orthogonal to
any matter if the argument being a data argument. Anyway, yes, that's
perfectly fine.
For f95, you do end you having to write an interface body, which I don't
like. At least you need that to get an explicit interface for the dummy
rpocedure. If the dummy does not need an explicit interface, you can
just go with the EXTERNAL statement instead of an interface body, but I
don't much like that either.
As discussed in the other replies, f2003 provides what I see as
"cleaner" alternatives using the new PROCEDURE statement. The PROCEDURE
statement is much more parallel in form to type specification
statements, including the allowance for atributes such as OPTIONAL. You
can use an abstract interface with a PROCEDURE statement. That still has
you writing an interface body, but at least you can then potentially
reference that abstract interface in multiple places instead of having
to repeat it each time. Alternatively, you can use the feature of the
PROCEDURE statement that says, in essence, "use the same interface as
this other procedure, whose interface you already know." That avoids
having to write an interface body at all. But all of those require
f2003.
For f95, you are stuck with either an interface body or the external
statement/attribute. Also for f95, you have to use a separate OPTIONAL
statement (except in the case of an implicit interface function, where
you could use the optional attribute on the type specification
statement).
P.S. One other case where you have to write an interface body is for
calling non-Fortran procedures. For me, that's far more common than
having procedure dummy arguments.
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain