可分配的数组值函数。 gfortran vs ifort [英] Allocatable array valued function. gfortran vs ifort
问题描述
function allocateArray(size)
integer,allocatable,dimension(:) :: allocateArray
整数大小
allocate(allocateArray(size))
结束函数allocateArray
来自主程序
< pre $ integer,allocatable,dimension(:) :: a
a = allocateArray(10)
print *,allocated(a)
在版本17.0.1之前编译ifort时,默认行为是编译器不要将Fortran规则用于内在赋值的自动分配。
您需要使用之类的选项--assume realloc-lhs
。
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
From the main program
integer, allocatable, dimension(:) :: a
a = allocateArray(10)
print *, allocated(a)
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.
You will need to use an option like -assume realloc-lhs
.
这篇关于可分配的数组值函数。 gfortran vs ifort的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!