Re: optional or interface



Mike <SulfateIon@xxxxxxxxx> wrote:

On Jun 4, 1:28 am, Arjen Markus <arjen.mar...@xxxxxxxxxx> wrote:

Interface bodies come in quite handy for situations where you can not
put the routine in a module:...

Do you mean to name two procedures in different modules using
INTERFACE? like this:

No, he doesn't mean that. Getting the terminology at least a little bit
straight here might help some.

He is talking about interface *BODIES*. You aren't showing any of those.
What you have is interface *BLOCKS*.

Interface blocks are those things that start with an INTERFACE
statement. They can be used for several different things. (I regard that
as a bit unfortunate and confusing; I wish the functionalities were more
cleanly separated).

One of the things that an interface block can be used for is to define a
generic procedure. Your description of this as "naming proceures" is a
bit confusing, albeit at least sort of true. Procedures have names
already. Defining a generic does also give the proceduyres a generic
name, it is tue. But the "generic" part of that is important to
understanding what is going on.

A completely separate thing that can sometimes be done with an interface
block is to put an interface body in it, which defines an explicit
interface. An interface body is one of those things that looks like a
subroutine or function, but without the "guts"; it just has
declarations. You cannot use it for a module procedure, as a module
procedure already has an explicit interface. Reread Arjen's post, where
he says that they are handy

for situations where you can not put the routine in a module

That has no connection at all with the example you showed, since your
routines are in modules.

module mB
contains
subroutine bbb()
end subroutine bbb
end module mB

module mA
use mB
interface aaabbb
module procedure aaa
module procedure bbb
end interface aaabbb
contains
subroutine aaa()
end subroutine aaa
end module mA

I've found it is not allowed.

Well, this has nothing at all to do with what Arjen was talking about,
or with much of the rest of this thread, but I might as well correct it
also.

The only problem with the above code is that you have an ambiguous
generic; there are two subroutines in the same generic that cannot be
distinguished. This has *ZERO* to do with them being from separate
modules. If you change one of those subroutines (for example, add a
non-optional dummy argument to either one), then the above code is just
fine (and I checked to make sure that g95 agreed with me).

I think this just reflects the confusions caused by referring to generic
interface bodies as "giving names to procedures". That obscures the fact
that you are defining a generic and thus need to follow the rules for
generics - specifically the rules for disambiguability (which I know is
a mouthful of a word).

--
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: Optional function arguments, how?
    ... Overload the interface with a stub/driver routine ... subroutine DefaultFunc!--default routine ... end module NewFun ...
    (comp.lang.fortran)
  • Re: how to find the type of an object represented by an interface
    ... Simplifying, generics are strictly linked to compilation, not runtime. ... template parameter T must implement particular interface i.e. IDisposable: ... Readonly property MaximumRange() as Integer ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: .NET 2.0 to be launched on Nov 8
    ... Generics in .NET don't need interfaces to work, ... >> and probably Delphi for Win32 RSN. ... > - I also wonder if you can parameterise a template with an interface. ...
    (borland.public.delphi.non-technical)
  • 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: 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)