Implicit procedure pointer

Implicit procedure pointer


is there a way to determine on runtime if a procedure pointer with implicit interface is pointing to a subrotine or a function? Or even better is it possible to check such a pointer against a range of possible explicit interfaces in form of abstract interfaces defined in the code? 

Thanks for the replies!

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

You can use ASSOCIATED on a procedure pointer to determine if it is associated at all. You can't compare to an interface, but what you can do is declare and pre-associate some fixed pointers that point to specific procedures, and then test against those. Here's an example:

implicit none
procedure() :: suba
procedure() :: subb
procedure(), pointer :: pp => null()
procedure(), pointer :: pa, pb
integer which
print *, "Before assignment, is pp associated?", associated(pp)
pa => suba
pb => subb
mainloop: do
write (*,'(A)', advance='no') "Enter 1 for SUBA, 2 for SUBB, 0 to exit: "
read (*,*) which
if (which == 1) then
  pp => suba
else if (which == 2) then
  pp => subb
else if (which == 0) then
  exit mainloop
end if
if (associated(pp,pa)) then
  print *, "pp is associated with suba"
else if (associated (pp,pb)) then
  print *, "pp is associated with subb"
  print *, "pp is associated with something else"
end if
end do mainloop
subroutine suba
subroutine subb

Steve - Intel Developer Support

Leave a Comment

Please sign in to add a comment. Not a member? Join today