可分配的数组值函数。 gfortran vs ifort [英] Allocatable array valued function. gfortran vs ifort

查看:238
本文介绍了可分配的数组值函数。 gfortran vs ifort的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么ifort和gfortran在这里有不同的行为?用ifort编译它返回false并且gfortran为真。我之前在自己的代码中遇到了这个问题,并决定使用子例程,但最近的一个问题让我质疑了这种行为。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆