Exa*_*ale 4 fortran gfortran intel-fortran
为什么ifort和gfortran之间有不同的行为?用ifort编译它返回false并且gfortran为true.我之前在自己的代码中遇到了这个问题并决定使用子程序,但最近的一个问题让我质疑这种行为.
function allocateArray(size)
integer, allocatable, dimension(:) :: allocateArray
integer size
allocate(allocateArray(size))
end function allocateArray
Run Code Online (Sandbox Code Playgroud)
从主程序
integer, allocatable, dimension(:) :: a
a = allocateArray(10)
print *, allocated(a)
Run Code Online (Sandbox Code Playgroud)
在版本17.0.1之前使用ifort进行编译时,默认行为是编译器不使用Fortran规则对内部赋值进行自动分配.
你需要使用像这样的选项-assume realloc-lhs.