(j3.2006) (SC22WG5.4520) Callback functions with polymorphic arguments
Bader, Reinhold
Reinhold.Bader
Wed Aug 31 15:41:33 EDT 2011
Hello all,
consider the following module:
module mod_callback_up_01
implicit none
abstract interface
subroutine callback(data)
class(*), dimension(:) :: data ! (A)
end subroutine
end interface
contains
subroutine foo(data, proc)
class(*), dimension(:) :: data ! (B)
procedure(callback) :: proc
call proc(data)
end subroutine
end module
and then the following code which uses this module:
module mod_impl
implicit none
type :: bar
integer :: i
end type
contains
subroutine callback1(data)
class(bar) :: data(:) ! (C)
integer :: i
do i=1,size(data)
data(i)%i = i
end do
end subroutine
end module
program prog
use mod_callback_up_01
use mod_impl
integer, parameter :: dim=5
type(bar) :: x(dim)
call foo(x, callback1)
end program
Questions:
(1) Is the above code standard conforming?
(2) Assume that at (C), the declaration is replaced by
type(bar) :: data(:)
Is the resulting code standard conforming?
(3) Assume that at (A) and (B), class(*) is replaced by
class(base), where base is some known type, and
bar is an extension of base.
Is the resulting code standard conforming?
(4) Apply both assumptions in (2) and (3) - is the
resulting code then standard conforming?
The background for this is the issue of handling callbacks in MPI-3.
For backward compatibility it is considered desirable to have
abstract interfaces for callbacks which use arguments declared
as TYPE(*), DIMENSION(*). The dummy arguments of the callbacks
of course will have some definite type in existing code. (The
programmer may still need to add BIND(C), but this is considered
sufficiently low-intrusive). Depending on the answers to above questions,
something may need to be done about this in the TR.
(For the above code, different compilers give widely varying results
with respect to both compilation and run time behaviour).
Regards
Reinhold
More information about the J3
mailing list