【发布时间】:2015-11-26 16:59:04
【问题描述】:
我注意到 gfortran 有一个奇怪的行为,我使用的版本是
GNU Fortran (MacPorts gcc5 5.2.0_0) 5.2.0
我的操作系统是 OS X YOSEMITE 10.10.3 (14D136)
我运行以下代码
program test
implicit none
type :: mytype
real(kind=8),dimension(:,:,:),allocatable :: f
end type
type(mytype),dimension(:,:),allocatable :: tab
integer i,j
allocate(tab(3,8))
do i=1,3
do j=1,8
allocate(tab(i,j)%f(i,i,i))
enddo
enddo
call check_shapes(tab(:,1))
contains
subroutine check_shapes(arg)
integer :: n,k
type(mytype),dimension(:) :: arg
n=size(arg)
do k=1,n
print*,shape(arg(k)%f)
enddo
end subroutine
end program
输出符合预期
1 1 1
2 2 2
3 3 3
但是,改变我在子程序中定义虚拟参数的方式
type(mytype),dimension(:) :: arg
到
class(mytype),dimension(:) :: arg
为虚拟参数引入一个类而不是类型,我有以下输出
2 2 2
3 3 3
1 1 1
这是一个错误吗?或者我错过了什么?
请注意,它适用于 ifort 版本 Intel(R) 64,版本 15.0.3.187 Build 20150408
【问题讨论】:
-
或者更可能是这个,查看最后一条评论及其代码gcc.gnu.org/bugzilla/show_bug.cgi?id=58043 绝对是一个错误。
-
我已经用 gfortran 4.8.3 进行了复制。似乎固定在树干上。
-
我已经用 5.2.1 转载了。
-
这个补丁 gcc.gnu.org/ml/fortran/2015-07/msg00038.html 改变了很多,也许值得检查哪些打开的错误仍然相关。
标签: debugging fortran gfortran derived-types