boo*_*see 6 fortran pointers procedure function
我正在尝试使用过程指针(Fortran 2003中的新功能)指向元素函数,但它不起作用.我真的需要函数,ELEMENTAL并需要一个指向它的指针.在Fortran中指向元素函数真的不可能吗?
module elemfunc
implicit none
contains
elemental function fun111(x) result(y)
real*8, intent(in) :: x
real*8 :: y
y = x**2+1
end function fun111
end module elemfunc
program testptr
use elemfunc
implicit none
interface
elemental function func (z)
real*8 :: func
real*8, intent (in) :: z
end function func
end interface
procedure (func), pointer :: ptr
ptr => fun111
print *, ptr( (/1.0d0,2.0d0/) )
end program testptr
Run Code Online (Sandbox Code Playgroud)
错误信息:
main.f90:12.7:ptr=>fun111
1
Nonintrinstic elemental procedure pointer 'func111' is invalid in procedure pointer assignment at (1)
Run Code Online (Sandbox Code Playgroud)
在 fortran 2003 标准的段落中7.4.2 Pointer Assignment明确指出这是不允许的:
C728 (R742) The proc-target shall not be a nonintrinsic elemental procedure
Run Code Online (Sandbox Code Playgroud)
(这个限制在 fortran 2008 标准中仍然存在,所以还没有放松。)