Fortran 可分配数组值函数。格弗特兰vs伊弗特兰

Fortran 可分配数组值函数。格弗特兰vs伊弗特兰,fortran,gfortran,intel-fortran,Fortran,Gfortran,Intel Fortran,为什么ifort和gfortran在这里有不同的行为?使用ifort编译,返回false,使用gfortran返回true。我以前在自己的代码中遇到过这个问题,并决定改用一个子例程,但最近的一个问题使我对这种行为产生了疑问 function allocateArray(size) integer, allocatable, dimension(:) :: allocateArray integer size allocate(allocateArray(size))

为什么ifort和gfortran在这里有不同的行为?使用ifort编译,返回false,使用gfortran返回true。我以前在自己的代码中遇到过这个问题,并决定改用一个子例程,但最近的一个问题使我对这种行为产生了疑问

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)

使用17.0.1版之前的ifort进行编译时,默认行为是编译器不使用Fortran规则在内部赋值时自动分配

您需要使用类似于
-假设realloc lhs
的选项