可分配数组值函数.gfortran 与 ifort [英] Allocatable array valued function. gfortran vs ifort
问题描述
为什么这里的 ifort 和 gfortran 有不同的行为?使用 ifort 编译返回 false,使用 gfortran 返回 true.我之前在自己的代码中遇到过这个问题,并决定改用子例程,但最近的一个问题让我质疑这种行为.
Why is there different behavior between ifort and gfortran here? Compiled with ifort it returns false and with gfortran true. I ran into this problem before in my own code and decided to use a subroutine instead, but a recent question made me question this behavior.
function allocateArray(size)
integer, allocatable, dimension(:) :: allocateArray
integer size
allocate(allocateArray(size))
end function allocateArray
从主程序
integer, allocatable, dimension(:) :: a
a = allocateArray(10)
print *, allocated(a)
推荐答案
使用 ifort 17.0.1 之前的版本进行编译时,默认行为是编译器不使用 Fortran 规则进行内在赋值的自动分配.
When compiling with ifort before version 17.0.1, the default behaviour is for the compiler not to use the Fortran rules for automatic allocation on intrinsic assignment.
您将需要使用像 -assume realloc-lhs
这样的选项.
You will need to use an option like -assume realloc-lhs
.
这篇关于可分配数组值函数.gfortran 与 ifort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!