Re: Explicit interface of a type-bound procedure bounded to an instance (F2003)

Skip to first unread message

Richard E Maine

Nov 12, 2004, 2:50:14 PM11/12/04
Apologies in advance for any syntax errors. I don't actually have a
compiler to play with this stuff yet, so my actual experience with
the syntax is still zero. (Pablo) writes:

> Now, the question here is, what's the explicit interface with which I
> have to declare the procedure pointer variable? In other words, what's
> the explicit interface of an instance bounded type-bound procedure?

I don't like the term "type-bound procedure" because I find it
misleading. Alas, that is the term the standard uses. The term
invites you to think of being type-bound as a property of the
procedure, but in fact it is not. The procedure is a plain old
procedure that need not even "know" that there is a type binding
for it. Thus I prefer to use the term "procedure type binding"
to indicate that there is a type binding to the procedure, rather
that that the procedure itself is somehow modified by this binding.

With that in mind, the answer to your question should be a little
more clear. The procedure has the same interface as it would have
if there were not a binding for it. Namely, if the procedure is your

> function method(self, x) result(y)
> class(AClass), intent(in) :: self
> real, intent(in) :: x
> real :: y
> y = x ** 2
> end function method

then a suitable abstract interface could be written as

abstract interface
function some_name(self, x) result(y)
class(AClass), intent(in) :: self
real, intent(in) :: x
real :: y
end function some_name
end abstract interface

and you could declare a suitable pointer as

procedure(some_name), pointer :: f

Note that if the function method was accessible, you could dispense
with the abstract interface and write just

procedure(method), pointer :: f

This probably isn't quite what you were trying to do, but I don't
think it is possible to do quite what you wanted, if I understood
correctly. In particular, note that, however you declare it, f is a
pointer to a function with *2* (not 1) arguments. In the type-bound
form, the first argument was automagically provided because of the
PASS attribute of the binding. There is nothing corresponding to the
PASS attribute for an ordinary old procedure pointer (unless it is a
procedure pointer component) because the procedure pointer doesn't
have any way of saying what to pass. There isn't a form of a
(noncomponent) procedure pointer that says that it points to a
specified procedure and, by the way, always provide this actual
argument for one of the dummies.

So if you have done

f => aninstance%method

you will need to invoke f with 2 arguments like

write (*,*) f(aninstance,x)

instead of like

write (*,*) f(x)

There isn't a way to make the pointer f "remember" that aninstance
should be the first argument.

Now if f is a procedure pointer component, that's diffferent; procedure
pointer components can have passed-object arguments just like procedure
type bindings, because there is an "obvious" object to pass (the object
that the pointer is a coomponent of).

Richard Maine | Good judgment comes from experience;
email: my first.last at org.domain | experience comes from bad judgment.
org: nasa, domain: gov | -- Mark Twain

Reply all
Reply to author
0 new messages