(j3.2006) Procedure(), pointer: subroutine vs. function and implicit typing
Tobias Burnus
burnus at net-b.de
Fri May 15 07:55:10 EDT 2009
Malcolm Cohen wrote:
> Tobias Burnus wrote:
> > if (do_the_subroutine) then
> > proc_pointer => some_subroutine
> > call proc_pointer(5)
> > else
> > proc_pointer => some_function
> > y = proc_pointer(7)
> > end if
> >
> > "If proc-pointer-object has an implicit interface and is explicitly
> > typed or referenced as a function, proc-target shall be a function. If
> > proc-pointer-object has an implicit interface and is referenced as a
> > subroutine, proc-target shall be a subroutine."
> >
> Why would this not apply?
> It makes your example invalid
I then assume that the following is also invalid, but that a compiler is
not required to catch it:
module m
procedure(), pointer :: ptr
end module m
subroutine one()
use m
external sub
ptr => sub
call ptr()
end subroutine
subroutine two()
use m
external func
ptr => func
z = ptr()
end subroutine two
While the following is valid:
module m
type t
procedure(), pointer :: ptr
end type t
type(t) :: ptr1, ptr2
end module m
subroutine one()
use m
implicit none
external sub
ptr1%ptr => sub
call ptr1%ptr()
end subroutine
subroutine two()
use m
implicit none
real func, z
external func
ptr2%ptr => func
z = ptr2%ptr()
end subroutine two
Is this correct?
Tobias
More information about the J3
mailing list