The code at the end uses a generic name (SWAP) in two modules both of
which are used in a program. The code is accepted by the DEC and
VAST/f90 compilers but not by Imagine's F compiler.
In Metcalf&Reid (M+R, F90 explained, page 98) I find under overloading
and generic interfaces:
"... Furthermore, a generic name may be the same as another
accessible generic name. In such a case, all the procedures
that have this generic name may be invoked through it. ..."
The question here is what is meant by "accessible". DEC and Vast seem to
have a different interpretation than F. Since, as in the example below,
the compiler can always determine whether a violation of Fortran rules
for generic interfaces occurs, the Dec/Vast interpretation seems fine
and allows for more flexible programming.
Actually, the example goes a little towards generic programming but
without templates. (This Fortran feature can be used to code a
template-like module and use subsequent substitution to generate specific
modules:
module <type>_swap_module
public :: swap
private :: <type>_swap
interface swap
module procedure <type>_swap
end interface
contains
subroutine <type>_swap( a, b )
<TYPE>, intent(in out) :: a, b
<TYPE> :: temp
temp = a
a = b
b = temp
end subroutine <type>_swap
end module <type>_swap_module
Just substitute <TYPE> with the needed type-declaration and <type>
with a suitable name.
I would be interested to know whether the code below is REALLY standard
conforming.
If not, why not.
If yes, why F disallows this useful feature. (This is of course only
directed at the F inventors/maintainers.)
Cheers,
WWS
!-------------------------------------------------------------------------
! Example Code:
! kept in F style, F error originates from use of both modules
! in program test_swap.
!
!ERROR (#10289) on line number: nn !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!This module brings in a public name that is not unique. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
!-------------------------------------------------------------------------
module int_swap_module
public :: swap
private :: int_swap
interface swap
module procedure int_swap
end interface
contains
subroutine int_swap( a, b )
integer, intent(in out) :: a, b
integer :: temp
temp = a
a = b
b = temp
end subroutine int_swap
end module int_swap_module
module real_swap_module
public :: swap
private :: real_swap
interface swap
module procedure real_swap
end interface
contains
subroutine real_swap( a, b )
real, intent(in out) :: a, b
real :: temp
temp = a
a = b
b = temp
end subroutine real_swap
end module real_swap_module
program test_swap
use int_swap_module
use real_swap_module
real :: x, y
integer :: i, k
x = 1.0
y = 2.0
i = 1
k = 2
write(unit=*,fmt="(A,2F8.2)") "x,y before swap: ", x,y
call swap( x, y )
write(unit=*,fmt="(A,2F8.2)") "x,y after swap: ", x,y
write(unit=*,fmt="(A,2I8.2)") "i,k before swap: ", i,k
call swap( i, k )
write(unit=*,fmt="(A,2I8.2)") "i,k after swap: ", i,k
stop
end program test_swap
-----------------------------------------------------------------------
| Werner W Schulz |
| Dept of Chemistry email: [log in to unmask] |
| University of Cambridge Phone: (+44) (0)1223 336 502 |
| Lensfield Road Secretary: 1223 336 338 |
| Cambridge CB2 1EW Fax: 1223 336 536 |
| United Kingdom WWW: |
-----------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|