Prev: ENTRY statement
Next: Namelist/module-question
From: Tobias Burnus on 30 Sep 2009 17:52 >> It then works fine on the Nag compiler. It also works fine with gfortran 4.3/4.4/4.5 > I don't have the NAG compiler... :/ Well, you could then try either another compiler, e.g. gfortran*, or you do what Richard did: Move the interface before the "contains" line of the module (global scope of the module). Tobias * For gfortran binaries, see http://gcc.gnu.org/wiki/GFortranBinaries The official site (http://www.cygwin.com/) ships "gcc4" with GCC/gfortran 4.3.2; some 4.5-experimental builds are available via the GFortranBinaries page. For MinGW ("native Windows builds") there exists several places, e.g. the offical MinGW page which has 4.4.x. Disclaimer: I am a gfortran developer.
From: James Van Buskirk on 30 Sep 2009 18:24 "Richard Maine" <nospam(a)see.signature> wrote in message news:1j6ulkf.1tutz55a65xkwN%nospam(a)see.signature... > As an aside, one doesn't "normally" use a generic interface just for > renaming; it is more to allow multiple procedures to share the same > name. It can sort of be used for renaming, but as that isn't really the > purpose, some gotchas can result. For example, you can't pass a generic > procedure as an actual argument. I'm not sure whether renaming was the > sole purpose of it here or whether that was just the result of (helpful) > simplification for posting. There is another way to attempt renaming that works if the target procedure is compatible with BIND(C) rules: C:\gfortran\clf\rename_proc>type rename_proc.f90 module mod implicit none private public :: func, subr contains function func() result(res) bind(C,name='MySecretFunctionName') use ISO_C_BINDING, only: C_FLOAT real(C_FLOAT) :: res real, parameter :: one = 1. res = one write(*,'(a)') 'Succeeded in invoking func!' end function func subroutine subr(x) interface function newname() result(res) bind(C,name='MySecretFunctionName') use ISO_C_BINDING, only: C_FLOAT implicit none ! else result variable is implicitly typed real(C_FLOAT) res end function newname end interface real, intent(out) :: x x = more_fun(newname) end subroutine subr function more_fun(fun) result(res) real res interface function fun() result(res) bind(C) use ISO_C_BINDING, only: C_FLOAT implicit none ! else result variable is implicitly typed real(C_FLOAT) res end function fun end interface res = fun() end function more_fun end module mod program prog use mod, only : subr real :: x call subr(x) write(*,*) x end program prog C:\gfortran\clf\rename_proc>gfortran -Wall rename_proc.f90 -orename_proc C:\gfortran\clf\rename_proc>rename_proc Succeeded in invoking func! 1.0000000 -- write(*,*) transfer((/17.392111325966148d0,6.5794487871554595D-85, & 6.0134700243160014d-154/),(/'x'/)); end
From: helvio on 30 Sep 2009 18:40 On Sep 30, 10:52 pm, Tobias Burnus <bur...(a)net-b.de> wrote: > >> It then works fine on the Nag compiler. > > It also works fine with gfortran 4.3/4.4/4.5 Ok, I tried gfortran and it works just fine. Seems like I can use this little trick to rename procedures after all! :) But I'll try to be careful, since this seems to be a non-standard way of using interfaces. Note: I also use interface blocks in the standard way! ;) -- helvio
From: steve on 30 Sep 2009 19:00 On Sep 30, 3:40 pm, helvio <helvio.vairin...(a)googlemail.com> wrote: > On Sep 30, 10:52 pm, Tobias Burnus <bur...(a)net-b.de> wrote: > > > >> It then works fine on the Nag compiler. > > > It also works fine with gfortran 4.3/4.4/4.5 > > Ok, I tried gfortran and it works just fine. Seems like I can use this > little trick to rename procedures after all! :) But I'll try to be > careful, since this seems to be a non-standard way of using > interfaces. Note: I also use interface blocks in the standard way! ;) AFIAK, it is a completely Standard conforming method to "rename" the function. If a compiler doesn't work, then it is probably a bug in that compiler. Note, I'm too lazy and too busy to go read the Standard at the moment to verify this claim. module mod implicit none private public :: func, subr contains function func() result(res) real :: res real, parameter :: one = 1. res = one end function func subroutine subr(x) real, intent(out) :: x interface newname module procedure func end interface x = newname() end subroutine subr end module mod program prog use mod, only : subr real :: x call subr(x) write(*,*) x end program prog
From: Richard Maine on 30 Sep 2009 20:59
steve <kargls(a)comcast.net> wrote: > On Sep 30, 3:40 pm, helvio <helvio.vairin...(a)googlemail.com> wrote: > > On Sep 30, 10:52 pm, Tobias Burnus <bur...(a)net-b.de> wrote: > > > > > >> It then works fine on the Nag compiler. > > > > > It also works fine with gfortran 4.3/4.4/4.5 > > > > Ok, I tried gfortran and it works just fine. Seems like I can use this > > little trick to rename procedures after all! :) But I'll try to be > > careful, since this seems to be a non-standard way of using > > interfaces. Note: I also use interface blocks in the standard way! ;) > > AFIAK, it is a completely Standard conforming method to "rename" > the function. If a compiler doesn't work, then it is probably a bug > in that compiler. Yes, it is standard conforming. When I said > As an aside, one doesn't "normally" use a generic interface just for > renaming; it is more to allow multiple procedures to share the same > name. It can sort of be used for renaming, but as that isn't really the > purpose, some gotchas can result. That was not to imply in any way that this wasn't standard conforming. There are many things that I would not consider "normal", but are perfectly standard conforming. However, I will continue to insist that this does not "rename" the function. This gives the function a generic name in addition to its specific one. That is not the same thing as renaming. It can seem similar on the surface in limited circumstances. I do see that you quoted "rename". I'm just emphasizing that the quotes are very much needed. I don't like referring to it that way because as soon as you do so, someone will ignore the quotes and think it really is a renaming... and then they will wonder why it doesn't work like they would expect. -- Richard Maine | Good judgment comes from experience; email: last name at domain . net | experience comes from bad judgment. domain: summertriangle | -- Mark Twain |