在内部类型上重载 Fortran 内部运算符?
对于代码
module pow_mod
implicit none
integer, parameter :: dp = kind(1.0d0)
interface operator(**)
module procedure mypow
end interface
contains
!
function mypow(x,y) result(x_to_y)
real(kind=dp), intent(in) :: x,y
real(kind=dp) :: x_to_y
x_to_y = exp(y*log(x))
end function mypow
end module pow_mod
gfortran 所说的
pow_fast.f90:5:25:
5 | module procedure mypow
| 1
Error: Operator interface at (1) conflicts with intrinsic interface
和 Intel Fortran 所说的类似。 Fortran 中是否可以重载内在类型上的内在运算符?
For the code
module pow_mod
implicit none
integer, parameter :: dp = kind(1.0d0)
interface operator(**)
module procedure mypow
end interface
contains
!
function mypow(x,y) result(x_to_y)
real(kind=dp), intent(in) :: x,y
real(kind=dp) :: x_to_y
x_to_y = exp(y*log(x))
end function mypow
end module pow_mod
gfortran says
pow_fast.f90:5:25:
5 | module procedure mypow
| 1
Error: Operator interface at (1) conflicts with intrinsic interface
and Intel Fortran says something similar. Is it possible in Fortran to overload intrinsic operators on intrinsic types?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不允许有这样的定义操作。从 Fortran 2018 (15.4.3.4.2) 开始:
It is not allowed to have a defined operation like this. From Fortran 2018 (15.4.3.4.2):
这是Fortran 2018中的这种限制所禁止的
This is forbidden by this restriction in Fortran 2018