- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I change function to the form of subroutine, there is no such a problem.
implicit none
type test_type
procedure(fun_interface), nopass, pointer :: fun_ptr
procedure(sub_interface), nopass, pointer :: sub_ptr
end type test_type
abstract interface
function fun_interface(n,x) result(f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end function fun_interface
subroutinesub_interface(n,x,f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end subroutine sub_interface
end interface
contains
subroutinetest_type_constructor(test, fun,sub)
interface
function fun(n,x) result(f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end function fun
subroutinesub(n,x,f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end subroutine sub
end interface
type(test_type) :: test
test%fun_ptr => fun;
test%sub_ptr => sub;
end subroutine test_type_constructor
end module type_module
module funcs
implicit none
contains
function fun1 (n,x ) result (f )
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
! try this
f = 2.0*x ;
! or this , both give WRONG results
callsub1(n,x,f)
end function fun1
subroutine sub1(n,x,f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
f = 2.0*x ;
end subroutine sub1
end module funcs
program main
use type_module
use funcs
type(test_type) :: test
integer :: n =2 ;
double precision :: x(2), f(2)
call test_type_constructor (test, fun1, sub1)
x = (/-1.d0, 1.d0/);
f = 0.d0;
calltest%sub_ptr(n,x,f)
print *, " f from call fun ", f;
f = test%fun_ptr(n,x);
print *, " f from call fun ", f;
! This does not work in ifort.
print *, " size of returned value from fun_ptr ", size(test%fun_ptr(n,x));
end program
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
this has been a problem area. Let me investigate.
ron
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
issue number is DPD200151942
simplified case to:
module type_module
implicit none
abstract interface
function fun_interface(n,x) result(f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end function fun_interface
subroutine sub_interface(n,x,f)
integer, intent(in) :: n
double precision, intent(in) :: x(n)
double precision :: f(n)
end subroutine sub_interface
end interface
type test_type
procedure(fun_interface), nopass, pointer :: fun_ptr
procedure(sub_interface), nopass, pointer :: sub_ptr
end type test_type
end module type_module
program main
use type_module
type(test_type) :: test
integer :: n = 2 ;
double precision :: x(2), f(2)
! This does not work in ifort.
print *, " size of returned value from fun_ptr ", size(test%fun_ptr(n,x));
end program
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
This bug was fixed in the 12.0 compiler. It was also fixed in the 11.1 Update 7, 11.1.073 compiler
closing this now.
ron

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page