I wish to use ‘subroutine pointers’ in a program. The following example program should make it clear just what I mean by ‘subroutine pointers’:
program sptest
implicit none
interface
subroutine fgeneric
end subroutine
end interface
pointer(p, fgeneric)
p=loc(mysub1)
!p=loc(mysub2)
call fgeneric
contains
subroutine mysub1
print*,'hello world'
end subroutine
subroutine mysub2
print*,'goodbye world'
end subroutine
end program sptest
Now, this compiles and runs just fine on Intel’s IVF but doesn’t compile with pgf95:
PGF90-S-0043-Illegal attempt to redefine symbol fgeneric (sptest.f90: 9)
Please can someone advise a suitable change to make to the above code to enable successful compilation on pgf95?
Cheers,
Rob
Hi Rob,
We don’t support procedure pointer yet, but are actively working on adding the F2003 implementation and should have it available later this year. As for your example using Cray pointers, this is not something we support directly but with a few modifications you can get it work.
Example:
% cat fpptr.f90
program sptest
implicit none
external fgeneric
pointer(p, fgeneric)
p=loc(mysub1)
call callgen(fgeneric)
p=loc(mysub2)
call callgen(fgeneric)
contains
subroutine callgen (subptr)
call subptr
end subroutine
subroutine mysub1
print*,'hello world'
end subroutine
subroutine mysub2
print*,'goodbye world'
end subroutine
end program sptest
% pgf90 -V8.0-5 fpptr.f90
penryn01:/tmp/qa% a.out
hello world
goodbye world
%
Hope this helps,
Mat
Mat,
What can I say? You are a superstar! Many thanks for taking the time to adjust my code.
I do look forward to using genuine F2003 procedure pointers soon, but in the mean time this will suffice for me.
Thank you, again.
Kind regards,
Rob