Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Implicit procedure pointer

Felix_F_1
Beginner
602 Views

Hello,

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!

0 Kudos
1 Reply
Steven_L_Intel1
Employee
602 Views

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:

[fortran]
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
else
  cycle
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"
else
  print *, "pp is associated with something else"
end if

end do mainloop

end

subroutine suba
end
subroutine subb
end
[/fortran]

0 Kudos
Reply