1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
!// objective: test different variants of interfaces in Fortran
!// check: namespacemymodule.xml
!// check: interfacemymodule_1_1genericproc.xml
!// check: interfacemymodule_1_1externalproc.xml
!// check: interfacemymodule_1_1abstractproc.xml
!// check: interfacemymodule_1_1operator_07_8cross_8_08.xml
!// check: interfacemymodule_1_1operator_07_2_2_08.xml
!// config: OPTIMIZE_FOR_FORTRAN=YES
!// config: WARN_IF_UNDOCUMENTED=NO
module myModule
implicit none
private
public :: genericProc
public :: externalProc
public :: abstractProc
! meaning 1: interface declaration for external proc, e.g. function declaration
! (the target is obviosly not in this module, so somewhere outside a module
! there is a function we want to use)
interface
real function externalProc(r)
real, intent(in) :: r
end function
end interface
! meaning 2: generic interface, e.g. function overloading
! (can be mixed with 1)
interface genericProc
module procedure firstProc
module procedure otherProc
subroutine externalProc2(r)
real, intent(out) :: r
end subroutine
end interface
! meaning 3: abstract interface, e.g. for function pointers, deferred methods
! (this is more like a typedef, but needs to be handled similarly to a function definition)
abstract interface
subroutine abstractProc(logicalArg)
logical, intent(out) :: logicalArg
end subroutine
end interface
! meaning 2 again, this time as user defined operator
interface operator(.cross.)
module procedure cross_product
end interface
! meaning 2 again, this time for overloading an existing operator
interface operator(//)
module procedure cross_product
end interface
contains
!> short doc
subroutine firstProc(i)
integer, intent(in) :: i !< integer argument
end subroutine
subroutine secondProc(r)
real, intent(out) :: r
end subroutine
subroutine otherProc(someArg)
character(len=*), intent(in) :: someArg
end subroutine
pure function cross_product(v, w)
real, intent(in) :: v(3), w(3)
real :: cross_product(3)
!cross_product = ...
end function
end module myModule
|