我不知道我是遇到编译器错误还是遗漏了什么。我正在尝试运行以下代码:
program test
implicit none
integer, parameter :: dp=kind(1.d0)
integer, allocatable :: int_mat(:,:)
integer, allocatable :: int_mat_2(:,:)
real(dp), allocatable :: real_mat(:,:)
allocate(int_mat(2,2))
int_mat = 0
int_mat_2 = int_mat
real_mat = int_mat ! Falls over here.
end program
编译运行
nagfor (flags: -f2003 -C=all)
按预期工作。编译运行 gfortran (flags: -std=f2003 -fcheck=all)
运行时失败并显示错误消息:At line 13 of file test.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'real_mat' (1/2)
我希望代码成功,如
int_mat_2
和 real_mat
应该隐式分配。这对于 int_mat_2
来说似乎是正确的但不适用于 real_mat
.我已经用各种 gfortran 版本(5.4、6.3、7.0)尝试过这个,并且都有同样的问题。
最佳答案
由 francescalus 发现,这是 this compiler bug ,此后已针对更新的 gfortran 版本进行了修复。
关于fortran - 从整数转换为实数(dp)时自动分配失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46039931/