Tobias:
It's not possible in Fortran 90 or Fortran 95, but in Fortran 2003 or
Fortran 2008 you can define an abstract interface thus:
abstract interface
subroutine F ( Arg )
real :: Arg
end subroutine F
end interface
You can then access that interface either within the same scope as its
definition, or by use or host association, and declare a procedure
pointer, procedure dummy argument, or type-bound procedure by reference
to it:
subroutine Some_Sub ( A, My_F )
real :: A
procedure(F) :: My_F
....
end subroutine Some_Sub
See subclauses 4.5.3, 4.5.4, 12.3.2.1 and 12.3.2.3 of
http://j3-fortran.org/doc/year/04/04-007.pdf.
On Thu, 2010-08-05 at 15:09 -0700, Tobias Brandt wrote:
> Hi all,
> I'm just starting out with Fortran 90 coming from C++ and need some
> help. In C++ you can define a function pointer type like so:
>
>
> typedef void (*mytype) (float);
>
>
> and then use it as a type for function parameters:
>
>
> void some_function (float a, mytype f)
> {
> f(a);
> }
>
>
> void some_other_function (float a, mytype f)
> {
> f(2*a);
> }
>
>
>
>
> Now, if I want to do the same in Fortran 90, I have to define the same
> inteface twice:
>
>
> subroutine some_sub (a, f)
> real :: a
> interface
> subroutine f (arg)
> real :: arg
> end subroutine
> end interface
> call f(a)
> end subroutine
>
>
> subroutine some_sub (a, f)
> real :: a
> interface
> subroutine f (arg)
> real :: arg
> end subroutine
> end interface
> call f(2*a)
> end subroutine
>
>
>
>
> Is it possible to somehow "reuse" the interface definition by
> declaring it outside the subroutines or in a different module?
>
>
> Regards,
> Tobias
|